Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Problem In PHP.. (http://www.greenguysboard.com/board/showthread.php?t=639)

chaldoray 2003-09-10 03:03 AM

Problem In PHP..
 
Ok i am making a tracking script to track my users go here http://www.bishopbeater.com/trackingclicks.php it says

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mnt2/users/jonhill/jonhill/bishopbeater.com/html/trackingclicks.php on line 5

heres my code for trackingclicks.php

mysql_pconnect("mysql.4ph.com","jonhill","changeme");
mysql_select_db("counter");
$result = mysql_query("select * from counter WHERE url=\'$url\'");
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$count=$r["count"];
$url=$r["url"];
$count++;

$update = "UPDATE counter SET count=\'$count\' WHERE id=$id";
$updatesql = mysql_query($update);
?>



if anyone can help me id appreciate it thanks.

AcidMaX 2003-09-11 12:47 PM

Is $url being set? Are there any rows in the DB that have that URL? To me it seems like there is an error causing MySQL to barf. Maybe the url column name is wrong? Can you post the db layout?

Andy

iSC_Luke 2003-09-11 02:13 PM

chaldoray,
It looks like either you don't connect to your DB Server successfully, or most likely, there is an error in your query.

Try this to see what the problem is:
PHP Code:

<? 
if ( mysql_pconnect("mysql.4ph.com","jonhill","changeme") === FALSE)
    echo 
"ERROR: Could Not Successfully Connect to DB Server\nSQL ERROR:".mysql_error()."\n";
if ( 
mysql_select_db("counter") === FALSE)
    echo 
"ERROR: Could Not Select Database\nSQL ERROR:".mysql_error()."\n";

if ( (
$result mysql_query("select * from counter WHERE url='$url'")) === FALSE)
    echo 
"ERROR: Error executing query:\nSQL ERROR:".mysql_error()."\n";

while(
$r=mysql_fetch_array($result)) 

$id=$r["id"]; 
$count=$r["count"]; 
$url=$r["url"]; 
$count++; 

$update "UPDATE counter SET count='$count' WHERE id=$id"
$updatesql mysql_query($update); 
?> 
<script language="JavaScript"> 
document.location.href="<?php echo $url;?>
</script> 
<? ?>

Hope this helps ;)

iSC_Luke 2003-09-11 02:19 PM

This code won't execute the script if there is an error with the SQL Query:
PHP Code:

<? 
if ( mysql_pconnect("mysql.4ph.com","jonhill","changeme") === FALSE)
    echo 
"ERROR: Could Not Successfully Connect to DB Server\nSQL ERROR:".mysql_error()."\n";
if ( 
mysql_select_db("counter") === FALSE)
    echo 
"ERROR: Could Not Select Database\nSQL ERROR:".mysql_error()."\n";

if ( (
$result mysql_query("select * from counter WHERE url='$url'")) === FALSE)
    echo 
"ERROR: Error executing query:\nSQL ERROR:".mysql_error()."\n";
else {
    while(
$r=mysql_fetch_array($result)) { 
        
$id=$r["id"]; 
        
$count=$r["count"]; 
        
$url=$r["url"]; 
        
$count++; 
        
        
$update "UPDATE counter SET count='$count' WHERE id=$id"
        
$updatesql mysql_query($update); 
?> 
    <script language="JavaScript"> 
    document.location.href="<?php echo $url;?>
    </script> 
<?
    
}
}
?>


chaldoray 2003-09-11 06:19 PM

What's a good script to track what links your surfers are clicking any good ones out their? If so please tell me, Also what are some good sites to learn more about php function like if else, etc.

iSC_Luke 2003-09-11 07:13 PM

chaldoray,

Quote:

What's a good script to track what links your surfers are clicking any good ones out their? If so please tell me
Don't know of any free scripts for that, but they must be out there - keep looking :) - There are gazzilions of free scripts out there.

Quote:

Also what are some good sites to learn more about php function like if else, etc.
If you would like to learn PHP, it's probably best to get a book, however if you need reference to PHP functions, http://www.php.net/ is your best bet. It has the entire PHP manual right there, which you can search.

P.S. 'if' and 'else' are not functions, but language conditional statements. - some info about them can be found here: http://ca2.php.net/else

Good Luck!

iSC_Luke 2003-09-11 07:15 PM

Here is another link explaining all about Control Structures

Hope this helps ;)

chaldoray 2003-09-12 12:12 AM

Thanks man im ok in php but i want to learn more about the dates and srand function and stuff, i have the book php for the worldwide web and master php 4.1

matt 2003-09-12 03:43 AM

I've found these resources quite useful in the past...

http://www.phpbuilder.com/
http://www.phpfreaks.com/



Matt

chaldoray 2003-09-12 01:20 PM

Hey matt, I submitted my free sites to your site pink n purple

RawAlex 2003-09-12 03:37 PM

You should always check after a query to make sure you have actual results, by:

$num_rows = mysql_num_rows ($result);

You might have an issue where you are getting more than one row returned, and as a result, the fetch_array will fail because you need to fetch_row instead.

Alex

venturi 2003-09-13 05:17 PM

Good point Alex!

Another tip is to always perform your own error handling. For example:
PHP Code:

<?php
$query 
"SELECT * FROM my_table WHERE my_field='some_value'";
// note that I preceed all mysql calls with @ to supress the default error handling
$result = @mysql_query($query);
// now I am testing to see if I get a valid result
if ( ! $result) {
  echo @
mysql_error();
  break;
}

// now I process the results
while ($my_row = @mysql_fetch_assoc($result)) {
  
// here I do something spectacular with the data
}
?>

|buddy|

chaldoray 2003-09-13 05:49 PM

Can you explain all that to me? Like how would i call my host and db and check it if its in db if its not give them a error and the code to check if they submitted a form etc, how can i learn more about the mktime like 3000 i want to learn more about date and times and such thanks.

venturi 2003-09-13 06:19 PM

Hop over to Script School and take TDavid's 16 part (you set the pace) course on PHP. That's where I started learning PHP and now it's what I do for my living. The course if free and full of information on most if not all of the questions you have.

Then hop over to amazon.com and grab a copy of this book: PHP Functions Essential Reference by Greant, Merral, Wilson & Michlitsch; published by New Riders. It's a great reference manual and is organized a bit more logically than the php.net manuals. I've had my copy for about 6 months now and I'm probably going to have to get a new copy of it by year's end because I've used and abused it so much. |waves|

chaldoray 2003-09-14 02:43 AM

Thanks man, I well go ahead and do that i already have php for the worldwide web book but it sucks is that book any good?

RawAlex 2003-09-14 12:21 PM

Venturi, in the case of this code, I don't think the error is a "no result" rather too many results. fetch_array doesn't like working much when there are multiple rows in the result (need to fetch_row).

Just doing:

$nums = mysql_num_rows($result);
print $nums;

will show how many rows are selected in the database. That would go a long way to explain what is happening after.

Alex

chaldoray 2003-09-14 11:54 PM

Anymore else i can learn? More of the functions so i can create my own scripts

RawAlex 2003-09-15 01:26 AM

I have SAMS PHP in 24 hours... it is actually quite useful. Admittedly, I have been programming other languages since, well, a long f-ing time, so maybe it just makes more sense to me. I have had a couple of php books, and this is the one that stays on my desk for reference.

php.net is a good place to get info on commands and comments from end users.

Alex

chaldoray 2003-09-15 01:34 AM

I have a couple of questions, i well be using php.net for functions how can i search new function in php.net? I am going to buy another book i have mastering php 4.1 now its a ok book.

Ok now, I made a login and stuff on my page, this is how i want it whenever someone clicks a link on my page pop-ups well come up if their not a registered user so they have to sign up to look at the page then when they sign up and login then when they go to a page they don't get the pop-ups and the page well show how can i do this in php?

How can you do that with .htaccess to so if your not a member on everypage you go pop-ups well come up until u register?

matt 2003-09-15 07:28 AM

Quote:

Originally posted by chaldoray
I have a couple of questions, i well be using php.net for functions how can i search new function in php.net?
I search for everything on php.net by typing in urls like this

php.net/fopen
php.net/while

That'll take you straight to the page you're looking for and it'll also list a heap of other functions in the menu.


btw thanks for submitting :)

chaldoray 2003-09-15 05:55 PM

I just bought 2 php books from borders. PHP ADVANCED FOR THE WORLD WIDE WEB, and sams teach yourself php in 24 hours, BTW, i can return the books in 30 days and get a refund, so I'm going to read them in like a week then return them cool huh? |bananna| I have 2 old php books that im going to sell on ebay.

chaldoray 2003-09-15 05:58 PM

What are some good marketing books i can pick up and read?


All times are GMT -4. The time now is 08:11 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc