konetch Posted July 6, 2009 Share Posted July 6, 2009 I have a contant form that submits some quotes into my database. To display the quotes from the database I have written a little code. <html> <body> <? mysql_connect ("localhost","root"); mysql_select_db ("cms"); $sql = "select * from mohdatabase"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $field1= $row["pageid"]; $field2= $row["quote"]; $field3= $row["author"]; echo "$field1<br>"; echo "$field2<br>"; echo "$field3<p>"; } ?> </body> </html> When I look at the page that this is on it shows the error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\konetcms\test\a\display.php on line 10 Would you know why? Thanks, I'm still new and couldn't find an answer. Alex Quote Link to comment https://forums.phpfreaks.com/topic/164885-solved-displaying-data/ Share on other sites More sharing options...
ldougherty Posted July 6, 2009 Share Posted July 6, 2009 Your SQL query is failing. More than likely your script is failing to connect to the database all together which would explain why the query fails. Use the or die mysql_error(); as this will display the problem. Quote Link to comment https://forums.phpfreaks.com/topic/164885-solved-displaying-data/#findComment-869501 Share on other sites More sharing options...
konetch Posted July 6, 2009 Author Share Posted July 6, 2009 Okay I changed it to <html> <body> <? mysql_connect ("localhost","root"); mysql_select_db ("cms"); $sql = "select * from mohdatabase"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) or die(mysql_error()); { $field1= $row["pageid"]; $field2= $row["quote"]; $field3= $row["author"]; echo "$field1<br>"; echo "$field2<br>"; echo "$field3<p>"; } ?> </body> </html> Is that correct. Now it says there is a parse error on line 10 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164885-solved-displaying-data/#findComment-869505 Share on other sites More sharing options...
pacchiee Posted July 6, 2009 Share Posted July 6, 2009 Since everything else seems to be fine, assuming there is no password for the user root, try editing your Line 4 to mysql_connect ("localhost","root",""); If you have set a password for user root, it should be something like this mysql_connect ("localhost","root","password"); Quote Link to comment https://forums.phpfreaks.com/topic/164885-solved-displaying-data/#findComment-869726 Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 change while ($row = mysql_fetch_array($result)) or die(mysql_error()); { to while($row=mysql_fetch_array($result)){ no ; and no die! Quote Link to comment https://forums.phpfreaks.com/topic/164885-solved-displaying-data/#findComment-869733 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.