$sql2 = "INSERT INTO `" . $tbl_name . "` ('reply_id', 'a_id', 'a_name', 'a_reply', 'a_datetime') VALUES ('" . $id . "', '" . $Max_id . "', '" . $a_name . "', '" . $a_reply . "', '" . $datetime . "')";
ERROR: The SQL Server said:
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 ''reply_id', 'a_id', 'a_name', 'a_reply', 'a_datetime') VALUES ('
('reply_id', 'a_id', 'a_name', 'a_reply', 'a_datetime')
(reply_id, a_id, a_name, a_reply, a_datetime)
It's the values that I have quotes around:The error you're seeing is because you have quotes around the column names.
Change
Code:('reply_id', 'a_id', 'a_name', 'a_reply', 'a_datetime')
to
Code:(reply_id, a_id, a_name, a_reply, a_datetime)
$sql2="INSERT INTO $tbl_name(reply_id, a_id, a_name, a_reply, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_reply', '$datetime')";
$result2=mysql_query($sql2);
Apologies, I think I was referring to some code that someone else posted that had quotes around the column names.It's the values that I have quotes around
Personally i'd build the query string first as a variable and pass that to mysql_query() - does the same thing but I find it easier to read and debug.
I just tried that and I got "Parse error: parse error in xyzdir/etc/etc.php"put back ticks around the table like so....
Code:$result2 = mysql_query("INSERT INTO `$tbl_name` (reply_id, a_id, a_name, a_reply, a_datetime) VALUES('$id', '$Max_id', '$a_name', '$a_reply', '$datetime')");
I just tried that and I got "Parse error: parse error in xyzdir/etc/etc.php"
I don't understand this error: "Duplicate entry '1' for key 1"
Ahhhhhhhh, and you Sir deserve a badge!I.e. if your Id field is a primary key, and you insert an id of 1234, and then later try and insert the same id, you will get that error.
Ahhhhhhhh, and you Sir deserve a badge!
I made the ID a primary key for strange reason
Whilst reading a dummies guide to php & mysql, one of the code examples included ob_start. Now after googling around it's an output buffer but I have no idea what it's used for. Could anyone please elaborate on what it is and what it's used for? Cheers
$sql="INSERT INTO $tbl_name(myusername, mypassword, email)VALUES('$myusername', '$mypassword', '$email')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo "<a href=resgistrationsuccess.php>Your Registration Was Successful!</a>";
}
else {
echo "ERROR: The SQL Server said:<br />" . mysql_error();
}
mysql_close();
?>