christofurr Posted June 1, 2007 Share Posted June 1, 2007 Shows a parse error when I access the page it's uploaded to. <html> <body> <?php /* PHP script for MySQL transactions */ $sql = mysql_connect(server_host,user,pass); if (!&sql) die('Error message.' . mysql_error()); else echo "Successful connect."; /* This orders some data to be displayed*/ mysql_select_db("database_name", $con); $selalldat = mysql_query("SELECT * FROM table_name"); while($shoalldat = mysql_fetch_row($selalldat)) { echo "<p>"; echo $shoalldat[1] . " " . $shoalldat[2] . " " . $shoalldat[3] . " " . $shoalldat[4] . " " . $shoalldat[5] . " " . $shoalldat[6] . " " . $shoalldat[7] . " " . $shoalldat[8] . " " . $shoalldat[9] . " " . $shoalldat[10] . " " . $shoalldat[11]; echo "</p>"; } mysql_close($sql); ?> </body> </html> My database has 11 columns and a dozen rows of information. I made sure that my connection information was correct. Where's my mistake? Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/ Share on other sites More sharing options...
btherl Posted June 1, 2007 Share Posted June 1, 2007 You wrote !&sql instead of !$sql Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-265999 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 Holy potatoes! That's it?? Stick around, please. I'll check if that fixes the problem. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266000 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 Still no dice... Parse error: parse error, unexpected T_STRING in * on line 9 * = directory hidden ??? Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266007 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 Are server_host, user and pass meant to be variables in this line? $sql = mysql_connect(server_host,user,pass); Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266009 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 Your also going to have trouble with this line as $con is not defined, should be $sql. mysql_select_db("database_name", $con); Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266010 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 No. I replaced those with my database login information in the actual script. The $con variable was another error. Let me switch it up and see if that fixes it. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266011 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 ps; I'll gibe you a tip nice and early. This is a good habit to get into. Always check your queries succeed and return a result before trying to use them. <?php if ($selalldat = mysql_query("SELECT * FROM table_name") && mysql_num_rows($selalldat)) { while($shoalldat = mysql_fetch_row($selalldat)) { echo "<p>"; echo $shoalldat[1] . " " . $shoalldat[2] . " " . $shoalldat[3] . " " . $shoalldat[4] . " " . $shoalldat[5] . " " . $shoalldat[6] . " " . $shoalldat[7] . " " . $shoalldat[8] . " " . $shoalldat[9] . " " . $shoalldat[10] . " " . $shoalldat[11]; echo "</p>"; } } mysql_close($sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266012 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 Not sure what you mean. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266013 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 Same parse error after correcting the variable. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266014 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 The $con variable was another error. Let me switch it up and see if that fixes it. Parse errors are caused by incorrect syntax. Using incorrect variables will generate other errors / warnings. the only thing I can see is a lack of curly braces around your first if. PHP should handle that OK though. if (!$sql) { die('Error message.' . mysql_error()); } else { echo "Successful connect."; } Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266015 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 Are the curly braces required with the if and else statements? I hadn't read that anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266016 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 No... there not required, but it is how most (if not all) people program php. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266018 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 Still nothing after adding braces. :'( Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266019 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 Post your current code. Dont change anything accept the password (for security reasons). Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266020 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 <html> <body> <?php /* PHP script for MySQL transactions */ $sql = mysql_connect(db946.perfora.net,dbo206008956,password); if (!$sql) { die('Connect failed.' . mysql_error()); } /* This orders some data to be displayed*/ mysql_select_db("db206008956", $sql); $selalldat = mysql_query("SELECT * FROM Users"); while($shoalldat = mysql_fetch_row($selalldat)) { echo "<p>"; echo $shoalldat[1] . " " . $shoalldat[2] . " " . $shoalldat[3] . " " . $shoalldat[4] . " " . $shoalldat[5] . " " . $shoalldat[6] . " " . $shoalldat[7] . " " . $shoalldat[8] . " " . $shoalldat[9] . " " . $shoalldat[10] . " " . $shoalldat[11]; echo "</p>"; } mysql_close($sql); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266021 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 I knew it. mysql_connect expects 3 strings. $sql = mysql_connect('db946.perfora.net','dbo206008956','password'); ps: You'll do well to follow my tip on checking your queries succeed before use. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266022 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 OOOH I SEEE. And does it matter if I use quotes instead of apostrophes? Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266024 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 And could you explain how the check is done and how it works? Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266025 Share on other sites More sharing options...
trq Posted June 1, 2007 Share Posted June 1, 2007 OOOH I SEEE. And does it matter if I use quotes instead of apostrophes? You can use single or double quotes. And could you explain how the check is done and how it works? Sure. An example. <?php $sql = "SELECT * FROM foo"; $result = mysql_query($sql); // because mysql_query returns false on failure or a result resource (remember that everything // other than false is considered true in php) on success its a good idea (can generate errors otherwsie) // to check it before trying to use it. if ($result) { // it is now safe to use $result. // you also want to make sure you actually got some results from your query. if (mysql_num_rows($result)) { // now... in here you can display your data. } else { // no data was retrieved by your query } } else { // its not safe to use result in here. } ?> Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266028 Share on other sites More sharing options...
christofurr Posted June 1, 2007 Author Share Posted June 1, 2007 Yeah, I think I'm getting it. Many thanks, Thorpe. I'd been seeking help for a few nights now. Hope you're around when the confusion really sets in. Quote Link to comment https://forums.phpfreaks.com/topic/53810-solved-first-script-first-problem/#findComment-266029 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.