Foser Posted May 23, 2007 Share Posted May 23, 2007 here is my script My error Parse error: syntax error, unexpected $end in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 14 <?php mysql_connect("localhost","root" , "password") or die (mysql_error()); echo "Connected To MySQL Successfully"; mysql_select_db("tutorial1") or die (mysql_error()); echo "<br>Connected To Database Successfully"; $personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']); mysql_query("INSERT INTO personal information (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error()); echo "You've submited this information. <br> name:" .$personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex]."; ?> What is weird is that the error is on the last line which is ?> What could be the problem? Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/ Share on other sites More sharing options...
kathas Posted May 23, 2007 Share Posted May 23, 2007 you forgot a semicolon here mysql_query("INSERT INTO personal information (name, age, sex) make it mysql_query("INSERT INTO personal information (name, age, sex); Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259831 Share on other sites More sharing options...
demon_athens Posted May 23, 2007 Share Posted May 23, 2007 echo "You've submited this information. <br> name:" .$personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex]."; to echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex']; Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259834 Share on other sites More sharing options...
Foser Posted May 23, 2007 Author Share Posted May 23, 2007 echo "You've submited this information. <br> name:" .$personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex]."; to echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex']; this worked better but the ; thing did not because it just created a new error. But now my error is: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259884 Share on other sites More sharing options...
emehrkay Posted May 23, 2007 Share Posted May 23, 2007 that typically means that you either forgot a simicolon or a closing curly brace Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259887 Share on other sites More sharing options...
Foser Posted May 23, 2007 Author Share Posted May 23, 2007 VALUES('$personaldata['name']','$personaldata['age']','$personaldata['sex']')"); or die(mysql_error()); Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 10 I dont see anything wrong :S but then again im not a pro in php Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259906 Share on other sites More sharing options...
Foser Posted May 23, 2007 Author Share Posted May 23, 2007 anyone would know what could be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259937 Share on other sites More sharing options...
per1os Posted May 23, 2007 Share Posted May 23, 2007 VALUES('$personaldata['name']','$personaldata['age']','$personaldata['sex']')"); or die(mysql_error()); TO VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')"); or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259958 Share on other sites More sharing options...
Foser Posted May 23, 2007 Author Share Posted May 23, 2007 VALUES('$personaldata['name']','$personaldata['age']','$personaldata['sex']')"); or die(mysql_error()); TO VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')"); or die(mysql_error()); i've done what you've said but apparenthly there is a new bug, Parse error: syntax error, unexpected T_VARIABLE in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 10 thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259973 Share on other sites More sharing options...
kenrbnsn Posted May 23, 2007 Share Posted May 23, 2007 You have an extra ";" in this line: <?php VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')"); or die(mysql_error()); ?> it should written as <?php VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')") or die(mysql_error()); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259975 Share on other sites More sharing options...
Foser Posted May 23, 2007 Author Share Posted May 23, 2007 You have an extra ";" in this line: <?php VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')"); or die(mysql_error()); ?> it should written as <?php VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')") or die(mysql_error()); ?> Ken if i dont put ; i get a seperate error also new error ater some tweaking Parse error: syntax error, unexpected $end in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 14 vtahst the value line Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260060 Share on other sites More sharing options...
AV1611 Posted May 23, 2007 Share Posted May 23, 2007 every time you use a ; in PHP it ends the command that the line started with. whatever is to the right is considered a new line and must have proper syntax. you can put an entire script on a single text line, but good luck in trying to figure out what it all means Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260064 Share on other sites More sharing options...
chigley Posted May 23, 2007 Share Posted May 23, 2007 Should it not be like this? Surely the double use of 's will cause problems. <?php mysql_query("INSERT INTO personal information (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]');") or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260069 Share on other sites More sharing options...
paul2463 Posted May 23, 2007 Share Posted May 23, 2007 <?php mysql_connect("localhost","root" , "password") or die (mysql_error()); echo "Connected To MySQL Successfully"; mysql_select_db("tutorial1") or die (mysql_error()); echo "<br>Connected To Database Successfully"; $personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']); mysql_query("INSERT INTO personal information (name, age, sex)VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error()); echo "You've submited this information. <br> name:". $personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260071 Share on other sites More sharing options...
per1os Posted May 23, 2007 Share Posted May 23, 2007 Dude, I would seriously read through this http://us2.php.net/manual/en/language.basic-syntax.php Learn the basic of the syntax's. Anytime you get a syntax error you are asking for help, really syntax errors should be the least of your worries and the easiest to correct. Do some reading and learn that you cannot use a single quote inside a string surrounded by single quotes you have to escape it. Same with double quotes and that every statement should have a semi-colon after it. and that anytime and if statement is made it should have a starting { and an ending }. That is just basics to programming, learn them first if you do not it will take you 20 years to program 10 lines of code because you always have to ask for help on any type of syntax error that is thrown. Reading is key. Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260073 Share on other sites More sharing options...
Foser Posted May 24, 2007 Author Share Posted May 24, 2007 <?php mysql_connect("localhost","root" , "password") or die (mysql_error()); echo "Connected To MySQL Successfully"; mysql_select_db("tutorial1") or die (mysql_error()); echo "<br>Connected To Database Successfully"; $personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']); mysql_query("INSERT INTO personal information (name, age, sex)VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error()); echo "You've submited this information. <br> name:". $personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex]; ?> That's what I had in the beguining, it's not working. :'( Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260589 Share on other sites More sharing options...
AndyB Posted May 24, 2007 Share Posted May 24, 2007 That's what I had in the beguining, it's not working. "Not working" covers a multitude of sins, so you really should be much more specific about the problem than that. Looking at the code you have, it appears that you have a database table named personal space information. INSERT INTO personal information ... That isn't going to work as it will be interpreted as a database table named personal and the random 'information' will be meaningless in the query string. Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260631 Share on other sites More sharing options...
Foser Posted May 25, 2007 Author Share Posted May 25, 2007 i changed it to personalinfo. <?php mysql_connect("localhost","root" , "password") or die (mysql_error()); echo "Connected To MySQL Successfully"; mysql_select_db("tutorial1") or die (mysql_error()); echo "<br>Connected To Database Successfully"; $personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']); mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error()); echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex']."; ?> I still get a $end error. I was thinking because in my html. becuase for the sex option i did a slide select menu. <select name="select"> <option value="M">Male</option> <option value="F">Female</option> </select> will crachar suport this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261446 Share on other sites More sharing options...
paul2463 Posted May 25, 2007 Share Posted May 25, 2007 if you have a look at your last echo statement in your above post and count the number of double quotes you have, they work in pairs, an opening one and closing one , enclosing a string object. You have 7 in that statement which is why if you look at your code block the closing php tag is red and not blue because you string object is still open, simple syntax problems such as that should be found straight away Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261470 Share on other sites More sharing options...
seb hughes Posted May 25, 2007 Share Posted May 25, 2007 i changed it to personalinfo. <?php mysql_connect("localhost","root" , "password") or die (mysql_error()); echo "Connected To MySQL Successfully"; mysql_select_db("tutorial1") or die (mysql_error()); echo "<br>Connected To Database Successfully"; $personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']); mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error()); echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex']."; ?> I still get a $end error. I was thinking because in my html. becuase for the sex option i did a slide select menu. <select name="select"> <option value="M">Male</option> <option value="F">Female</option> </select> will crachar suport this? thanks If i was you I wouldn't echo the "Connected To MySQL Successfully" & "Connected To Database Successfully" Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261486 Share on other sites More sharing options...
Foser Posted May 25, 2007 Author Share Posted May 25, 2007 I've listened to what you guys told me, But i really don't think the 2 first echos would have created an issue, but I have taken it off and also fixed the problem with my " stupid mistake. But I get an unexpected ";" command on my line 13. <?php mysql_connect("localhost","root" , "password") or die (mysql_error()); mysql_select_db("tutorial1") or die (mysql_error()); $personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']); mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error()); [color=red]echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'].; [/color] ?> the red echo is my line 13 Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261570 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2007 Share Posted May 25, 2007 You have an extra "." before the ";". Remove the "." <?php echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex']; ?> BTW, using [tags] in a doesn't work. You should indicate the line that you're referring to by adding a comment to the line. Ken Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261576 Share on other sites More sharing options...
Foser Posted May 25, 2007 Author Share Posted May 25, 2007 thanks, well obviously now you guys will know which line it is thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261578 Share on other sites More sharing options...
Foser Posted May 26, 2007 Author Share Posted May 26, 2007 I hate to bump but Been a few days I've been wanting to fix this... thanks Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261935 Share on other sites More sharing options...
per1os Posted May 26, 2007 Share Posted May 26, 2007 What the problem, I thought Ken solved it. Quote Link to comment https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-262076 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.