csull36 Posted May 10, 2009 Share Posted May 10, 2009 I have a php script that opens a database connection and then retrieves some info from a table. It has always worked without a problem, but suddenly today, I receive a parse error when I try to run the script on my localhost server. (My local server is set up with wampserver using Apache 2.2.11, PHP 5.2.9-1 and mySQL 5.1.32) This is the error message, and line 31 is the while statement below: Parse error: parse error in C:\wamp\www\script.php on line 31 $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $row = mysql_fetch_array($result); while($row = mysql_fetch_array($result)){ etc... What could have possibly happened that would cause this script to no longer work correctly? I did not modify anything in mySQL or Apache. I can no longer retrieve any data from the table. I know this is a fairly vague question, but any help would be greatly appreciated. Thanks, csull36 Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/ Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Take out the $row = mysql_fetch_array($result); line before that while loop. See if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830779 Share on other sites More sharing options...
csull36 Posted May 10, 2009 Author Share Posted May 10, 2009 Take out the $row = mysql_fetch_array($result); line before that while loop. See if that helps. Oops, sorry, that was an extra line in my post. The actual code doesn't have that. The thing is that the code worked perfectly fine up until now... Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830789 Share on other sites More sharing options...
Maq Posted May 10, 2009 Share Posted May 10, 2009 Looks fine to me... Can we see some lines before the query? Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830792 Share on other sites More sharing options...
csull36 Posted May 10, 2009 Author Share Posted May 10, 2009 Looks fine to me... Can we see some lines before the query? Sure, it looks like this: <?php $host="localhost"; $user="root"; $password="password"; $db_name="database"; mysql_connect("$host", "$user", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $tbl_name="tblteams"; I am pretty sure it is not a problem with the actual code, since it has always worked, but then again, I didn't change any server config settings or anything, so I am completely baffled... Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830799 Share on other sites More sharing options...
Maq Posted May 10, 2009 Share Posted May 10, 2009 Please use tags for proper formatting and syntax highlighting. That doesn't equal 31 lines... Parse error usually signifies a missing, colon, quote, bracket etc... Double check for these. Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830802 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2009 Share Posted May 10, 2009 Oops, sorry, that was an extra line in my post. The actual code doesn't have that. The fact that you are not posting actual accurate copy/pasted code means we cannot really help you. Post your actual code from the start of the file through line 31. xxxxxx out any sensitive information but don't change any syntax. Don't even change any of the php tags. Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830811 Share on other sites More sharing options...
csull36 Posted May 10, 2009 Author Share Posted May 10, 2009 sorry, here is the exact code. The parse error occurs here on line 19, on the open bracket for the while statement <?php $host="mysql"; // Host name $user="user"; // Mysql username $password="xxxx"; // Mysql password $db_name="database"; // Database name mysql_connect("$host", "$user", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $tbl_name="table"; // Table name $sql="SELECT * FROM $tbl_name WHERE id='1'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result)) { $var = $row['field1']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830882 Share on other sites More sharing options...
GingerRobot Posted May 10, 2009 Share Posted May 10, 2009 There's no syntax error there. Also, you previously said there was an error on line 31, now you're not posting 31 lines and it's migrated to line 19? Which is it? Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-830917 Share on other sites More sharing options...
csull36 Posted May 10, 2009 Author Share Posted May 10, 2009 There's no syntax error there. Also, you previously said there was an error on line 31, now you're not posting 31 lines and it's migrated to line 19? Which is it? I removed some comment lines so yes, the parse error is on line 19. I know there is no problem with the syntax. That is why this parse error is so confusing. Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-831035 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2009 Share Posted May 10, 2009 Either your php installation is corrupted, your file is corrupted (contains some non-printing character that is breaking the syntax), or you are not accurately showing what is in the file (when you post information that does not match up or starts randomly changing, you loose a lot a credibility because we only see the information you provide in your post.) I would recommend copy/pasting your code into a completely new file. If that does not work, attach your file to a post so that someone else can test it on their server (do you have a different server you can test on?) Do you have other php files that do work? What else have you done to troubleshoot the problem? Has anything been updated on your computer concerning your web server or php? Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-831048 Share on other sites More sharing options...
csull36 Posted May 10, 2009 Author Share Posted May 10, 2009 Either your php installation is corrupted, your file is corrupted (contains some non-printing character that is breaking the syntax), or you are not accurately showing what is in the file (when you post information that does not match up or starts randomly changing, you loose a lot a credibility because we only see the information you provide in your post.) I would recommend copy/pasting your code into a completely new file. If that does not work, attach your file to a post so that someone else can test it on their server (do you have a different server you can test on?) Do you have other php files that do work? What else have you done to troubleshoot the problem? Has anything been updated on your computer concerning your web server or php? I tested some other files that should also be working properly, and they also displayed parse errors, so it looks like my php or mySQL is corrupted. I was certain all along that the code syntax was fine (since it had always worked before). I am going to try re-installing php. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/157558-parse-error-when-pulling-data-from-mysql-database-table/#findComment-831059 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.