Jump to content

mysql_fetch_array() error


chris_rulez001

Recommended Posts

hi im getting these errors:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/thunderb/public_html/support/index.php on line 24

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/thunderb/public_html/support/index.php on line 62

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/thunderb/public_html/support/index.php on line 80

 

my php code:

 

<?php
session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="******"; // Mysql password
$db_name="************"; // Database name
$tbl_name4="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name");

$sql4="SELECT * FROM $tbl_name4 ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result4=mysql_query($sql4);

$rows4=mysql_fetch_array($result4);
?>
<title><?php echo $rows4['forumtitle']; ?> - Home</title>
<link rel="stylesheet" href="css/stylesheet.css" />
</head>

<body text="000000" bgcolor="F1F1F1" link="003399" vlink="003399" alink="003399">
<?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="******"; // Mysql password
$db_name="************"; // Database name
$tbl_name4="boards"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name");

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>

<?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="******"; // Mysql password
$db_name="************"; // Database name
$tbl_name1="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name");

$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);
?>

<?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="******"; // Mysql password
$db_name="************"; // Database name
$tbl_name1="topics"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name");

$sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result1=mysql_query($sql1);

$rows6=mysql_fetch_array($result1);
?>
<br />
<table border="0" width="92%" cellspacing="0" cellpadding="0" style="border-color:#000000" align="center">
<tr>
<td width="100%">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>

<td width="27%" height="50" align="center" bgcolor="F1F1F1" class="welcomebg"> </td>
<td width="73%" bgcolor="F1F1F1" class="welcomebg" align="center">
<p><font size="2">
<?php if (!isset($_SESSION['username']) == false) { echo "Welcome, ".$_SESSION['displayname']."<br/>"; } else{
echo "Welcome, Guest, Please <a href='login.php'>Login</a> or <a href='register.php'>Register</a><br/>"; }?>
<?php $date = date("l F d, g i a"); echo $date; ?>
</font><br /></p>
</td>
</tr>

</table>
</td>
</tr><tr>
<td align="center">
<table width="100%" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="100%" align="center">
<table border="0" width="100%" cellpadding="3" cellspacing="0" align="center">
<tr>
<td class="menubg" valign="middle" bgcolor="EFEFEF" align="center"><font size="1">
<a href="index.php">Home</a> <a href="help.php">Help</a> <a href="members.php">Members</a> <a href="view_profile.php">Profile</a><?php if ($_SESSION['username'] == "admin") { echo " <a href='admin.php'>Admin Panel</a>"; }else { echo ""; } ?>
<?php if (!isset($_SESSION['username']) == false) { echo " <a href='logout.php'>Logout</a>"; }else {
echo " <a href='login.php'>Login</a> <a href='register.php'>Register</a>"; } ?>
</font></td>
</tr>
</table>
</td>
</tr>
</table>

</td>
</tr>
</table>
<br />

<center></center><br />
<br />
<table width="92%" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" width="100%">
<br />
<a href="index.php" class="nav"><?php echo $rows4['forumtitle']; ?></a> :: Home
<br/>
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="000000" class="bordercolor">
<tr>
<td>
<table cellpadding="4" cellspacing="1" border="0" width="100%">
<tr>
<td class="titlebg" bgcolor="4080B0" colspan="2">
<font class="titletext" color="F1F1F1" size="-1"><b>Board Name</b></font></td>
<td class="titlebg" bgcolor="4080B0" width="1%" align="center"><font class="titletext" color="F1F1F1" size="-1"><b> Topics</b></font></td>
<td class="titlebg" bgcolor="4080B0" width="1%" align="center">
<font class="titletext" color="F1F1F1" size="-1"><b>Posts</b></font></td>
<td class="titlebg" bgcolor="4080B0" width="24%" align="center">
<font class="titletext" color="F1F1F1" size="-1"><b>Last Post</b></font></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td colspan="5" class="catbg" bgcolor="DADADA" height="18">
<font size="2" class="cattext" color="0E0E0E"><b><?php echo $rows['catogory']; ?></b></font></td>
</tr>
<tr>
<td class="windowbg" bgcolor="EFEFEF" width="8%" align="center" valign="middle"></td>
<td class="windowbg2" bgcolor="F6F6F6" align="left" width="66%" valign="top" style="cursor:pointer;" onClick="if(!pb_bubble)location.href='/index.cgi?board=updates';" onMouseOver="mouseOverHighlightCell(this);setWindowStatus('Upgrades / News Board');return true;" onmouseout="mouseOutHighlightCell(this);setWindowStatus('');return true;">
<font size="2"><a href="view_board.php?board=<?php echo $rows['board']; ?>"><?php echo $rows['boardname']; ?></a></font><br/>
<font size="1"><?php echo $rows['description']; ?><br/><?php if(empty($rows['mods']) == false) { echo "Moderators: <a href='view_profile.php?user=".$rows['mods']."'>".$rows['mods']."</a>"; } else { echo ""; } ?></font></td>
<td class="windowbg" bgcolor="EFEFEF" valign="middle" align="center" width="1%">
<font size="2"><? echo $rows['topics']; ?></font></td>
<td class="windowbg" bgcolor="EFEFEF" valign="middle" align="center" width="1%">
<font size="2"><? echo $rows['posts']; ?></font></td>
<td class="windowbg2" bgcolor="F6F6F6" width="24%" valign="top">
<font size="1"></font></td>
</tr>
<?php
// Exit looping and close connection
}
?>
<tr>
<td colspan="5" align="right" class="catbg" bgcolor="99FFCC" height="18"><font size="2" class="cattext" color="0E0E0E">Mark All Boards As Read <a href="/index.cgi?action=markallboardsread"></a></font></td>
</tr>
</table></td>
</tr>
</table>
<br/><br/>
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="000000" class="bordercolor" border="1">
<tr>
<td>
<table cellpadding="4" cellspacing="1" border="0" width="100%">
<tr>
<td bgcolor="99FFCC" class="titlebg" align="center" colspan="2">
<font class="text1" color="F1F1F1" size="2"><b>Info Center</b></font></td>
</tr>
<tr>
<td class="catbg" bgcolor="DADADA" colspan="2">
<font size="2" class="cattext" color="0E0E0E"><b>Forum Statistics</b></font></td>
</tr>
<tr>

<td class="windowbg2" bgcolor="F6F6F6" valign="top" align="center">
<table width="98%" cellpadding="3" align="center"><tr><td valign="top" align="left" width="60%">
<font size="1"><br/>
Last Updated Topic: by <br/>View the <a href="recent_posts.php">10 most recent posts</a> of this forum.</font>
</td>
<td valign="top" align="left" width="40%" style="border-color: #000000">
<font size="1"><?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="******"; // Mysql password
$db_name="************"; // Database name

$conn = mysql_connect("$host1","$username1","$password1");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database1,$conn) or die ("Could not open database");

$mysql2 = "SELECT * FROM users ORDER BY id DESC LIMIT 1";
$result2=mysql_query($mysql2);
$row3 = mysql_fetch_assoc($result2);
echo "Total Members: <a href='members.php'>".$row3['id']."</a><br/>";
echo "Newest Member: ";
if($rows1['username'] == admin) { echo "<a href='view_profile.php?user=".$rows1['username']."'><font color='#FF0000'>".$rows1['displayname']."</font></a>"; } else { echo "<a href='view_profile.php?user=".$rows1['username']."'>".$rows1['displayname']."</a>"; } ?></font></td>
</tr>
</table></td>
</tr>
<tr>
<td class="catbg" bgcolor="DADADA" colspan="2">
<font size="2" class="cattext" color="0E0E0E"><b>Today's Birthdays</b></font></td>
</tr>
<tr>

<td class="windowbg2" bgcolor="F6F6F6" valign="top">
<table width="98%" cellpadding="3" align="center">
<tr>
<td valign="top" align="left">
<font size="1">Nothing Here Yet!<br/></font></td>
</tr>
</table></td>
</tr>
<tr>
<td class="catbg" bgcolor="DADADA" colspan="2">
<font size="2" class="cattext" color="0E0E0E"><b>Users Online</b></font></td>
</tr>
<tr>

<td class="windowbg2" bgcolor="F6F6F6"><table width="98%" cellpadding="3" align="center">
<tr>
<td valign="top" align="left"><font size="1">
<?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="******"; // Mysql password
$db_name="************"; // Database name
$username = $_SESSION['username'];

$conn = mysql_connect("$host1","$username1","$password1");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database1,$conn) or die ("Could not open database");

$mysql2 = "SELECT * FROM users ORDER BY id DESC LIMIT 1";
$result2=mysql_query($mysql2) or die(mysql_error());//checking to see if the query was successful
$staff = array();
$members = array();
$num_staff = 0;
$num_members = 0;
$num_guests = 0;
$num_hidden = 0;
while($row = mysql_fetch_assoc($result2)){//you need a while loop here - my mistake originally
$usertype = $row['usertype'];
$username = $row['username'];//also assuming you have some field for the username
$hidden = $row['hidden'];//and perhaps a separate field for their hidden status
if($usertype == "staff" && $hidden != '1' && $_SESSION['username'] == true){//this may be a number representing staff rather than the text staff
$staff[] = $username;
$num_staff++;
}elseif($usertype == "member" && $hidden != '1'){
$members[] = $username;
$num_members++;
}
else {
$guests[] = $username;
$num_guests++;
}
}
echo 'Number of staff online: '.$num_staff.' | Number of members online: '.$num_members.' | Number of guests online: '.$num_guests.'<br/><br/>';

if ($_SESSION['username'] == true) { if (strpos($username, $row['user_level']) == "Thunderboards Staff") { echo "<a href='view_profile.php?user=".$_SESSION['username']."'><font color='#FF0000'>".$_SESSION['displayname']."</font></a>"; } else { echo "<a href='view_profile.php?user=".$_SESSION['username']."'>".$_SESSION['displayname']."</a>"; } } else { echo ""; }
?>
</font></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table> </td>
</tr>
</table>
<br/>
<div align="center"><?php include('includes/copyright.php'); echo $hosted; ?></div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/63731-mysql_fetch_array-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.