Page 1 of 1

php mysql insert

Posted: Tue Sep 09, 2008 10:40 pm
by ayfine
This is driving me crazy that I can't fix this.

When inserting into a table I get this error on my page: 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 ''user@domain.com' at line 1.

The code that is doing it is this

Code: Select all

$register = mysql_query("Insert into newsletter_users (email, keye, groupe, name) values ('{$_POST['email']}', $key, '0', '$name')") or die(mysql_error());
How do I fix this?

Re: php mysql insert

Posted: Wed Sep 10, 2008 1:59 am
by jaoudestudios
Use...

Code: Select all

 
$q = "INSERT INTO newsletter_users SET email = '".$_POST['email']."', keye = '".$key."', groupe = '0', name ='".$name."'"; // protect your queries against sql injection
$sql = mysql_query($q);
 

Re: php mysql insert

Posted: Wed Sep 10, 2008 4:30 pm
by ayfine
jaoudestudios wrote:Use...

Code: Select all

 
$q = "INSERT INTO newsletter_users SET email = '".$_POST['email']."', keye = '".$key."', groupe = '0', name ='".$name."'"; // protect your queries against sql injection
$sql = mysql_query($q);
 
I just tried that and I still get the same error as before.

Re: php mysql insert

Posted: Thu Sep 11, 2008 1:24 am
by jaoudestudios
echo out the query ($q) and copy and paste it here, then we can see exactly what is going wrong.