Southern Belle Posted March 27, 2009 Share Posted March 27, 2009 Hope someone can help me with the problem. From what I understand the error appears because of missing ; or tag. I don't see anything missing. I could be going blind though... I've been looking at this problem for a while. This is a VERY simple code and feel dumb that I can't find the problem. <?php $username = "****"; $password = "********"; $database = "*********"; mysql_connect(localhost, $username, $password); @mysql_select_db($database); $result = mysql_query("SELECT * FROM varieties WHERE type = 'vir' "); WHILE ($row = mysql_fetch_array($result) or die('Error: '.mysql_error () ) echo $row['variety']."<br>"; mysql_close(); ?> This is the error msg I get... Parse error: syntax error, unexpected T_ECHO line 21 Line 21 is, WHILE ($row = mysql_fetch_array($result) or die('Error: '.mysql_error () ) Any suggestions?? By the way... If I remove "die" from WHILE, I get this msg Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/ Share on other sites More sharing options...
Mark Baker Posted March 27, 2009 Share Posted March 27, 2009 Start by fixing your syntax error move the or die('Error: '.mysql_error () to your $result = mysql_query("SELECT * FROM varieties WHERE type = 'vir' "); Then while (condition) { action; } Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/#findComment-795201 Share on other sites More sharing options...
mtoynbee Posted March 27, 2009 Share Posted March 27, 2009 Missing ) in while loop and use {} brackets Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/#findComment-795202 Share on other sites More sharing options...
Southern Belle Posted March 27, 2009 Author Share Posted March 27, 2009 OK, I totally removed the die statement and added the braces (I thought they were optional if there was only one statement). So this is what the code looks like now: $result = mysql_query("SELECT * FROM varieties WHERE type = 'vir' "); WHILE ($row = mysql_fetch_array($result) ) { echo $row['variety']."<br>"; } I'm getting this error msg: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/#findComment-795342 Share on other sites More sharing options...
Mchl Posted March 27, 2009 Share Posted March 27, 2009 Just put a semicolon ; after Just place echo statement after WHILE ($row = mysql_fetch_array($result) or die('Error: '.mysql_error () ) into {} [edit] If my post doesnt make sense... do not worry... I'm prolly too sleepy to write meaningful posts... Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/#findComment-795347 Share on other sites More sharing options...
kenrbnsn Posted March 27, 2009 Share Posted March 27, 2009 You really should put the die statement on the mysql_query statement. I believe that "type" is a reserved word in mysql, so you need to surround it with backticks: <?php $q = "SELECT * FROM varieties WHERE `type` = 'vir'"; $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); while($row = mysql_fetch_assoc($result)) echo $row['variety'] . "<br>\n"; ?> Yes, braces are optional when there is only one statement. Ken Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/#findComment-795349 Share on other sites More sharing options...
Southern Belle Posted March 27, 2009 Author Share Posted March 27, 2009 Thanks! type must be a reserved word. Is there someplace (preferably online) to go to find out what the various error messages mean? Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/#findComment-795354 Share on other sites More sharing options...
mrMarcus Posted March 27, 2009 Share Posted March 27, 2009 OK, I totally removed the die statement and added the braces (I thought they were optional if there was only one statement). So this is what the code looks like now: $result = mysql_query("SELECT * FROM varieties WHERE type = 'vir' "); WHILE ($row = mysql_fetch_array($result) ) { echo $row['variety']."<br>"; } I'm getting this error msg: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource that error msg is telling you that your query is no good .. check the spelling of your table and field. Link to comment https://forums.phpfreaks.com/topic/151399-parse-error-syntax-error-unexpected-t_echo/#findComment-795356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.