acd17 Posted March 2, 2010 Share Posted March 2, 2010 OK, I am completely new to php so this is probably such a stupid thing i am overlooking. $sql = "insert into hits (ipaddr, referpage, thedate, thetime) values ("; $sql .= "'" . $_SERVER['REMOTE_ADDR'] . "', "; $sql .= "'index.php', "; $sql .= "'" . date('Y-m-d') . "', "; $sql .= "'" . date('H:i:s') . "')"; $result = mysql_query($sql) or die ("Error: " . $sql); OK, so when I go to this page, my error pops up with the $sql statement. Now to troubleshoot, I went and ran the $sql statement directly and it inserted the data directly into my table "hits". But for some reason when I open the page it will not insert the data into the table. I will really appreciate any help I get on this. EDIT: I spend 30 min trying to figure this out. Finally I give up and decide to post. Literally 30 secs. after I post I realized I forgot to link to my functions.php page which has my connect function. This always happens to me. Quote Link to comment https://forums.phpfreaks.com/topic/193944-cant-get-data-inserted-into-table/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 For debugging purposes, if you echo mysql_error() at some point after a query that fails, it will point you in the right direction of finding out why the query failed. In this case you would have gotten an error that mysql_query() attempted to create a database connection, because there was not one at the time the query was executed. Quote Link to comment https://forums.phpfreaks.com/topic/193944-cant-get-data-inserted-into-table/#findComment-1020664 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.