May 27, 201412 yr Hello, could someone explain why this isn't working please.Basically what I've got is: $sql="INSERT INTO Table1 (Name, Email) VALUES ('$_POST[Name],$_POST[Email]')"; What I want is for the Name to enter into the Name Column, and the Email to enter into the Email column.If I change it to: $sql="INSERT INTO Table1 (Name) VALUES ('$_POST[Name],$_POST[Email]')"; I can get the Name and the Email to both be entered into the Name column. Or if I change (Name) to (Email) I can get both to enter into the Email Column. So I know everything else is working fine.Thanks!
May 27, 201412 yr You have to set the closing ' for both. Correct is: $sql="INSERT INTO `Table1` (Name, Email) VALUES ('$_POST[Name]','$_POST[Email]')"; Edited May 27, 201412 yr by Kolix
May 27, 201412 yr Author Thanks!... For some reason when I copied and pasted what you wrote it was showing up an error. But when I removed { and } it worked!Much appreciated!!
May 27, 201412 yr Okay, I will remove the { } then from my post. Make sure you aren't vulnerable to SQL-injections. Filter the input from GET- and POST-variables. Edited May 27, 201412 yr by Kolix
May 27, 201412 yr are you using PDO if so look into binding parameters, if you are using mysql_* you can use mysql_real_escape_string($var) but you would be better off using PDO as the mysql_*functions are being depricated
Create an account or sign in to comment