Jump to content

Cant get data inserted into table


acd17

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/193944-cant-get-data-inserted-into-table/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.