Forum Moderators: coopster

Message Too Old, No Replies

PHP and MySQL

         

branmh

12:28 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



I'm making my first php and mysql page and need help


$insert = mysql_query("insert into $table values ('$week', '$date', '$time', '$ip', '$host', '$browser', '$referrer', '$query')", $dbh)
or die("Could not insert data because ".mysql_error());

The $table is 06 and I get this error message:

Could not insert data because You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '06 values ('23', '2005-06-07', '8:24:49', 'xx.#*$!.xxx.xx', ''

So what have I done wrong here?

timster

12:46 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like the value of your $table variable somehow got foobared and contains '06' instead of the table name.

Here's an example of an easy way to flush out SQL errors in your code:

$query = "insert into $table values ('$week', '$date', '$time', '$ip', '$host', '$browser', '$referrer', '$query')";

echo $query; # Comment out this line once it works

$insert = mysql_query($query, $dbh)
or die("Could not insert data because ".mysql_error());

branmh

1:32 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



Here is now the output:


insert into 06 values ('23', '2005-06-07', '9:31:27', 'xx.#*$!.xxx.xx', '', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4', '', '')Could not insert data because You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '06 values ('23', '2005-06-07', '9:31:27', 'xx.xxx.xxx.xx', '',

branmh

1:53 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



After renaming 06 to jun, I now get this message:


insert into jun values ('23', '2005-06-07', '9:52:16', 'xx.#*$!.xxx.xx', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4', '', '')Could not insert data because Column count doesn't match value count at row 1

mcibor

3:17 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the last post you forgot to put in host - therefore the error

Michal Cibor

branmh

3:28 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



I removed the host since it is also blank and added 'NULL' in the beginning of the values.

And all is working fine now.