Jump to content

mysql_query() failure


warjat
 Share

Recommended Posts

I've got a very simple script that records IP address of every page view. Here is the script:

 

$ip = $_SERVER['REMOTE_ADDR'];

$query = "INSERT INTO tracking VALUES ('', '1', '$ip')";

echo $query;

 

echo ("<hr>");

if (mysql_query($query)) {

echo ("INSERT OK");

} else {

echo ("INSERT failed");

}

 

FYI: the 1st value is "auto_increment" in the DB, therefore blank ('') in the query string, and the 2nd value "1" is just for the page number 1, as this script will be on other pages, with different numbers.

 

Now, when I go to this page, it outputs the query, and hr, and then "INSERT failed" and sure enough, no record gets added to the DB.

 

The strangest thing is, is that when I copy the query that the page shows, and paste it into mysqlPHPadmin's "SQL" section and run it, it executes fine, and a record gets added to the DB, however the page is unable to do that.

Any ideas?

 

PS: the connection (which I didn't paste in here) is fine, that's definitely not the problem.

Link to comment
Share on other sites

Thanks for your help, the mysql_error, is also what I was looking for, as I wasn't getting any messages that would let me know what the problem was.

Anyway, the problem was, that sure, my connection was correct, but it was to the wrong database, which doesn't have the "tracking" table I was trying to INSERT into. This also explains why I was able to copy and paste the code in phpmyadmin successfully.

Sometimes, 5 minutes away from the code allows for a breakthrough! :)

Thanks for you help.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.