php mysql insert

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

php mysql insert

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: php mysql insert

Post 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);
 
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

Re: php mysql insert

Post 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.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: php mysql insert

Post by jaoudestudios »

echo out the query ($q) and copy and paste it here, then we can see exactly what is going wrong.
Post Reply