need help with MySQl Statement for 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
vincenzobar
Forum Commoner
Posts: 95
Joined: Wed Nov 02, 2005 9:57 am

need help with MySQl Statement for insert

Post by vincenzobar »

Quick help on this any one

no matter what i try i error at the @ symbol

I wrote with set to make sure all values match to columns i already tried with VALUES() too

Code: Select all

$sql = "INSERT INTO ".$table."  SET name=$name, name2=$name2, email=".mysql_real_escape_string($email).", zip=$zip, create_date=$date";
Email comes from a form and i use extract($_POST)

no matter what i do even in as a variable like

$email = addslashes($email); It errors out
$email = addslashes($_REQUEST['email']); It errors out too

I even tried str_replace and it just errors at \@

Any one got any ideas?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

try putting quotes around it? i.e. '$email' ?
vincenzobar
Forum Commoner
Posts: 95
Joined: Wed Nov 02, 2005 9:57 am

Post by vincenzobar »

almost worked now it messing up with the insert

I even changed back to

Code: Select all

$sql = "INSERT INTO ".$table." (name, name2, email, zip, create_date)  VALUES($name, $name2, ".mysql_real_escape_string('$email').", $zip, $date)";
my error is

Unknown column 'vincenzo' in 'field list'

soooo close!
vincenzobar
Forum Commoner
Posts: 95
Joined: Wed Nov 02, 2005 9:57 am

Post by vincenzobar »

Code: Select all

$email = mysql_real_escape_string($email);

$sql = "INSERT INTO ".$table." VALUES('', '$name', '$name2', '$email', '$zip', '$date')";
FINALLY!!!!

thanks for the inspiration!
Post Reply