genext.brite Posted June 2, 2011 Share Posted June 2, 2011 Hii phpfreaks... I'm running a simple mysql insert statement and getting a Parse Error.My code is : <html> <body> <?php $con=mysql_connect("localhost","root",""); if(!$con) { die ('Can not connect to :' .mysql_error()); } mysql_select_db("brite",$con); $sql="insert into subjects VALUES('$_POST['subname']','$_POST]['submarks']','$_POST['subgrade']','T')"; mysql_close(); header('Location:subject.php'); <?> My help me someone ,I'm screwed trying to fight it. Thanx in advance. MOD EDIT: code tags added Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/ Share on other sites More sharing options...
Pikachu2000 Posted June 2, 2011 Share Posted June 2, 2011 1) Post in the correct forum - moving thread to PHP help 2) When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1224367 Share on other sites More sharing options...
genext.brite Posted June 2, 2011 Author Share Posted June 2, 2011 Thank u Mod for editing...Now Please help me if u can.Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1224378 Share on other sites More sharing options...
Pikachu2000 Posted June 2, 2011 Share Posted June 2, 2011 Although I suspect there will be other problems, try these changes. $sql="INSERT INTO subjects VALUES('{$_POST['subname']}', '{$_POST['submarks']}', '{$_POST['subgrade']}', 'T')"; AND ?> // NOT <?> Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1224382 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 It really annoys me when people say they are getting a parse error or syntax error or anything like that. Just POST the ERROR MESSAGE. K, thanks. Pikachu2000 should have nailed the parse error, though. Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1224387 Share on other sites More sharing options...
jcbones Posted June 2, 2011 Share Posted June 2, 2011 The insert statement will not cause an error, because it is never sent to the Database. You must use mysql_query($sql) to do that. Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1224394 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 It'll cause a parse error if he doesn't type it right. Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1224410 Share on other sites More sharing options...
Drummin Posted June 2, 2011 Share Posted June 2, 2011 Define the table rows these values are being added to. I just guessed, so change as needed. mysql_query("INSERT INTO subjects (subname, submarks, subgrade, whoknows) VALUES('$_POST['subname']','$_POST]['submarks']','$_POST['subgrade']','T')"); Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1224411 Share on other sites More sharing options...
genext.brite Posted June 4, 2011 Author Share Posted June 4, 2011 heyy...every1 ...I tried everything but still nothings working... and @Pikachu 2000- sir i evn tried that syntax but no gain. My exact error is - Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\My files\insert.php on line 10. Plzz someone help me.I'm helpless!!! Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1225033 Share on other sites More sharing options...
jcbones Posted June 4, 2011 Share Posted June 4, 2011 Try this: <html> <body> <?php $con=mysql_connect("localhost","root",""); if(!$con) { die ('Can not connect to :' .mysql_error()); } mysql_select_db("brite",$con); $sql="insert into subjects VALUES('{$_POST['subname']}','{$_POST['submarks']}','{$_POST['subgrade']}','T')"; mysql_query($sql) or trigger_error( mysql_error() ); mysql_close(); header('Location:subject.php'); exit(); ?> You had an extra bracket (]) around one of your $_POST variables. Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1225061 Share on other sites More sharing options...
genext.brite Posted June 4, 2011 Author Share Posted June 4, 2011 Thank You @jcbones...Its working now . how cud I miss to see the extra bracket,silly i'm. Thnk u once again. Quote Link to comment https://forums.phpfreaks.com/topic/238254-whats-the-error-in-this-insert-statement/#findComment-1225206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.