INSERT INTO - Wierd Error :\\

mail table at phpMyAdmin: Imageshack - thetable.jpg

<?php
// connect to data base
$mysql_link = mysql_connect('localhost' ,'CENSORD','CENSORD') or die("ERROR 001: Cannot connect to MySQL server. please contact system administration.");

if  (!mysql_select_db('CENSORD', $mysql_link))
{
	echo "Error 002: Could not select DataBase.";
}

	$query = "INSERT INTO mail (mailid,to,from,subject,message) VALUES('1' ,'2','3','test','test')";
	echo $query.'<BR>';
	mysql_query($query) 
		or die(mysql_error());  
?>

This is what i get on screen (the first line I print from $query)


INSERT INTO mail (mailid,to,from,subject,message) VALUES('1' ,'2','3','test','test')
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 'to,from,subject,message) VALUES('1' ,'2','3','test','test')' at line 1

Whats the problem?

try


$query = "INSERT INTO mail VALUES ('1' ,'2','3','test','test')";

Also if i was you id AUTO_INCREMENT mailid, then it would be the following:


$query = "INSERT INTO mail VALUES ('' ,'2','3','test','test')";

I changed the $query the first code you wrote and received this error:

INSERT INTO mail VALUES ('1' ,'2','3','test','test')
Column count doesn't match value count at row 1

I tried to make the mailid primary key and added auto increase…
and used the second $query with the first value ‘’
and still received the same error…

INSERT INTO mail VALUES ('' ,'2','3','test','test')
Column count doesn't match value count at row 1

backtick the field names


INSERT 
    INTO 
mail (
      `mailid`
    , `to`
    , `from`
    , `subject`
    , `message`
) VALUES (
      '1' 
    , '2'
    , '3'
    , 'test'
    , 'test'
    )";

if that doesnt work, run an insert query using phpMyAdmin or something similar and see how its constructed and if it runs.

FIXED:
I shouldn’t have named one of the column’s “from”
after I changed it’s working…