Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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