warjat Posted November 1, 2010 Share Posted November 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 1, 2010 Share Posted November 1, 2010 See what this gives you. } else { echo ("INSERT failed" . mysql_error()); } Quote Link to comment Share on other sites More sharing options...
warjat Posted November 1, 2010 Author Share Posted November 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.