RTS Posted October 14, 2006 Share Posted October 14, 2006 can someone tell me whats wrong with this script?[code]<?php $con = mysql_connect('localhost','ZackBabtkis','');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db('test', $con);$result = mysql_query('SELECT * FROM blogs WHERE Name=sada');while($row = mysql_fetch_array($result)) { echo '<table border=10 width=400 cellpadding=0 cellspacing=3><tr><td background=table.jpg>'; echo '<div align=left><font size=5><b>From:</b> '. (ucfirst($row['username'])); echo '<br>'; echo '<b>On:</b> ' . (ucfirst($row['Date'])); echo '<br>'; echo '<b>Subject:</b> ' . (ucfirst($row['Subject'])); echo '</font>'; }echo '</table>';mysql_close($con);?>[/code]I get [code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Library/WebServer/Documents/Blogs/test.php on line 7[/code] Link to comment https://forums.phpfreaks.com/topic/23947-help-with-script/ Share on other sites More sharing options...
Stooney Posted October 14, 2006 Share Posted October 14, 2006 you have [code]$result = mysql_query('SELECT * FROM blogs WHERE Name=sada');[/code]try[code]$result = @mysql_query("SELECT * FROM blogs WHERE Name='sada'");[/code]Also, might try checking that your table name is 'Name', might be 'name'. Link to comment https://forums.phpfreaks.com/topic/23947-help-with-script/#findComment-108844 Share on other sites More sharing options...
coldkill Posted October 14, 2006 Share Posted October 14, 2006 The result resource is probably returned FALSE on a falure. This could be due to the name being incorrect on the table or database etc. To check wether to query found anything use this[code]if( mysql_num_rows( $result ) == 0 ){ echo'Query failed to execute';}[/code]hope that helps,Cold Link to comment https://forums.phpfreaks.com/topic/23947-help-with-script/#findComment-108845 Share on other sites More sharing options...
play_ Posted October 14, 2006 Share Posted October 14, 2006 I also have a feeling that you capitalized the N on 'Name' on this line by accident:$result = mysql_query('SELECT * FROM blogs WHERE [b]Name[/b]=sada');i tend to do that alot.maybe it's just 'name' ? I also just noticed that you started a table inside the while loop. [code]while($row = mysql_fetch_array($result)) { echo '<table border=10 width=400 cellpadding=0 cellspacing=3>[/code]but you close the table [i]after[/i] the while loop[code] }echo '</table>';[/code]probably not what you want.You are opening/starting a bunch of tables, and not closing them. Link to comment https://forums.phpfreaks.com/topic/23947-help-with-script/#findComment-108849 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.