chris_rulez001 Posted July 24, 2007 Share Posted July 24, 2007 hi im getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/thunderboards.awardspace.co.uk/Support/index.php on line 18 my code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <?php $host="fdb1.awardspace.com"; // Host name $username="*****"; // Mysql username $password="********"; // Mysql password $db_name="*************"; // Database name $tbl_name1="*********"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result1=mysql_query($sql); $rows1=mysql_fetch_array($result1); ?> <?php $host="fdb1.awardspace.com"; // Host name $username="*****"; // Mysql username $password="********"; // Mysql password $db_name="*************"; // Database name $tbl_name1="*********"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title><?php echo $rows1['forumtitle']; ?> :: <?php $board = $_GET['board']; if ($board == true) { echo "«".$rows['board']."»"; } else { echo "« Index »"; } ?></title> <link rel="stylesheet" type="text/css" href="css/style.css" /> <link rel="stylesheet" type="text/css" href="css/print.css" /> </head> <body> <?php $host="fdb1.awardspace.com"; // Host name $username="*****"; // Mysql username $password="********"; // Mysql password $db_name="*************"; // Database name $tbl_name1="*********"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result1=mysql_query($sql); $rows1=mysql_fetch_array($result1); ?> <div align="center"> <table width="800" height="50"> <tr> <td><p align="center"><?php echo $rows1['forumtitle']; ?> :: <?php $board = $_GET['board']; if ($board == true) { echo "«".$rows['board']."»"; } else { echo "« Index »"; } ?> <br/><br/><?php $board = $_GET['board']; if ($board == true) { echo "«".$rows['board']."»"; } else { echo "« Index »"; } ?></p> <table cellpadding="0" cellspacing="0" border="0" align="center" style="margin-left: 10px;"> <tr> <td class="maintab_active_first"></td> <td valign="top" class="maintab_active_back"> <a href="index.php">Home</a> </td><td class="maintab_active_last"> </td> <td valign="top" class="maintab_back"> <a href="help.php">Help</a> </td> <td valign="top" class="maintab_back"> <a href="profile.php">Profile</a> </td> <td valign="top" class="maintab_back"> <a href="members.php">Members</a> </td> <td class="maintab_last" valign="top"> <?php if (!isset($_SESSION['username']) == false) echo "<td valign='top' class='maintab_back'> <a href='logout.php'>Logout</a> </td>"; else{ echo "<td valign='top' class='maintab_back'> <a href='login.php'>Login</a> </td> <td valign='top' class='maintab_back'> <a href='register.php'>Register</a> </td>"; }?> </tr> </table> </td> </tr> </table> </div> <?php $host="fdb1.awardspace.com"; // Host name $username="*****"; // Mysql username $password="********"; // Mysql password $db_name="*************"; // Database name $tbl_name1="*********"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <div align="center"> <?php $board = $_GET['board']; if ($board == false) { echo "<table width='90%' border='0' align='center' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'> <tr> <td width='3%' align='center' bgcolor='#E6E6E6'><strong></strong></td> <td width='40%' align='center' bgcolor='#E6E6E6'><strong>Board</strong></td> <td width='27%' align='center' bgcolor='#E6E6E6'><strong>Topics</strong></td> <td width='16%' align='center' bgcolor='#E6E6E6'><strong>Posts</strong></td> <td width='14%' align='center' bgcolor='#E6E6E6'><strong>Last Post</strong></td> </tr>"; while($rows=mysql_fetch_array($result)){ // Start looping table row echo "<tr> <td align='center' bgcolor='#FFFFFF'></td> <td bgcolor='#FFFFFF'><a href='?board=".$rows['board']."'>".$rows['board']."</a><BR></td> <td align='center' bgcolor='#FFFFFF'>".$rows['topics']."</td> <td align='center' bgcolor='#FFFFFF'>".$rows['posts']."</td> <td align='center' bgcolor='#FFFFFF'>".$rows['lastpost']."</td> </tr>"; } } else { echo "<html><head><title><Your Forum> :: ".$board."</title></head> <body>This is a Board</body></html>"; } ?> </div> <?php // Exit looping and close connection mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#E6E6E6"></td> </tr> </table> </body> </html> can someone help me please? Link to comment https://forums.phpfreaks.com/topic/61623-solved-mysql_fetch_array-error/ Share on other sites More sharing options...
Trium918 Posted July 24, 2007 Share Posted July 24, 2007 <?php $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // syntax error. $sql1 instead of $sql $result1=mysql_query($sql); // change to $result1=mysql_query($sql1); ?> Link to comment https://forums.phpfreaks.com/topic/61623-solved-mysql_fetch_array-error/#findComment-306706 Share on other sites More sharing options...
suttercain Posted July 24, 2007 Share Posted July 24, 2007 Try this: $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result1=mysql_query($sql1); $rows1=mysql_fetch_array($result1); Link to comment https://forums.phpfreaks.com/topic/61623-solved-mysql_fetch_array-error/#findComment-306708 Share on other sites More sharing options...
trq Posted July 24, 2007 Share Posted July 24, 2007 Always check your queries actually work before trying to use them. the general syntax should be... <?php $sql="SELECT * FROM $tbl_name1 ORDER BY id DESC"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); } else { // no record found. } } else { // query failed. good place to debug, eg; echo "Query failed<br />" . mysql_error() . "$sql<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/61623-solved-mysql_fetch_array-error/#findComment-306714 Share on other sites More sharing options...
Trium918 Posted July 24, 2007 Share Posted July 24, 2007 thorpe is right, but make sure the syntax is correct. <?php $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; if ($result1 = mysql_query($sql1)) { if (mysql_num_rows($result1)) { $rows1 = mysql_fetch_array($result1); } else { // no record found. } } else { // query failed. good place to debug, eg; echo "Query failed<br />" . mysql_error() . "$sql1<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/61623-solved-mysql_fetch_array-error/#findComment-306719 Share on other sites More sharing options...
chris_rulez001 Posted July 24, 2007 Author Share Posted July 24, 2007 thanks all of you for your help Link to comment https://forums.phpfreaks.com/topic/61623-solved-mysql_fetch_array-error/#findComment-306722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.