Hey,
I have a script I am working on and am getting a parse error on this line. I think the end part is not coded right. Could someone see if they can spot any obvious mistakes?
$sql5 = "INSERT INTO answers (userid, qqid, answer) VALUES ('$user_id', '$qqid', '$_POST['{$qqid}']')";
Cheers,
Neil
rctneil:
Hey,
I have a script I am working on and am getting a parse error on this line. I think the end part is not coded right. Could someone see if they can spot any obvious mistakes?
$sql5 = "INSERT INTO answers (userid, qqid, answer) VALUES ('$user_id', '$qqid', '$_POST['{$qqid}']')";
Cheers,
Neil
‘$_POST[’{$qqid}‘]’)";
You’re using quotes inside quotes…try escaping the string for a moment.
‘".$_POST[’{$qqid}‘]."’)";
'{$_POST[$qqid]}')";
But you should never use user input in a query without validating it first.
So better would be:
$sql5 = "
INSERT INTO answers (userid, qqid, answer)
VALUES (
'$user_id'
, '$qqid'
, '" . mysql_real_escape_string($_POST[$qqid]) . "'
)
";
I understand that, but what I need is that it works first of all.
I have altered it to:
$currentanswer = $_POST['{$qqid}'];
$sql5 = "INSERT INTO answers (userid, qqid, answer) VALUES ('$user_id', '$qqid', '$currentanswer')";
I am getting undefined index on the $qqid varibale on the top line?
yeah, i dont know why you need that… I think what you’re trying to do is $_POST[$qqid] (which works fine)…
No, you’re getting undefined index on ‘{$qqid}’, because it should be $qqid
Why don’t you try my code?