Digitry Designs Posted January 25, 2010 Share Posted January 25, 2010 Hello, I am struggling with this. I am trying to create a list box that is populated by a mysql data base. I am running this script alone to figure it out before I add it to my working form. I keep getting this error: Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\list\list.php on line 10 I believe it has something to do with $result but why? <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("time_sheets") or die(mysql_error()); $result = @mysql_query("SELECT jobs FROM job"); print "<p>Select a Job:\n"; print "<select name="jobs">\n"; while ($row = mysql_fetch_assoc($result)) { $jobs = $row['jobs']; print "<option value=$jobs>\n"; } print "</select>\n"; print "</p>\n"; ?> can anyone help me with this. I am complete newb so explinations as simple as possible are extremely welcome, however, all help is very appreciated. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/189668-parse-error-unexpected-t_string/ Share on other sites More sharing options...
MadTechie Posted January 25, 2010 Share Posted January 25, 2010 you need to escape the quotes ie print "<select name="jobs">\n"; should be print "<select name=\"jobs\">\n"; Quote Link to comment https://forums.phpfreaks.com/topic/189668-parse-error-unexpected-t_string/#findComment-1001011 Share on other sites More sharing options...
Digitry Designs Posted January 25, 2010 Author Share Posted January 25, 2010 you need to escape the quotes ie print "<select name="jobs">\n"; should be print "<select name=\"jobs\">\n"; That worked great!! do you mind if I ask why? what do the slashes do? Quote Link to comment https://forums.phpfreaks.com/topic/189668-parse-error-unexpected-t_string/#findComment-1001016 Share on other sites More sharing options...
MadTechie Posted January 25, 2010 Share Posted January 25, 2010 okay if i do this echo "Hello World"; PHP echos the string between the quotes, BUT echo "Hello "world""; doesn't make sense! so i need to tell PHP that some of the quotes i wish to echo, to do this i "escape them" with the slash echo "Hello \"world\""; you could also use single quotes ie echo 'Hello "world" '; Quote Link to comment https://forums.phpfreaks.com/topic/189668-parse-error-unexpected-t_string/#findComment-1001019 Share on other sites More sharing options...
Digitry Designs Posted January 25, 2010 Author Share Posted January 25, 2010 okay if i do this echo "Hello World"; PHP echos the string between the quotes, BUT echo "Hello "world""; doesn't make sense! so i need to tell PHP that some of the quotes i wish to echo, to do this i "escape them" with the slash echo "Hello \"world\""; you could also use single quotes ie echo 'Hello "world" '; Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/189668-parse-error-unexpected-t_string/#findComment-1001021 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.