Jump to content

multiple mysql_fetch_array problems


yobo

Recommended Posts

hey all,

 

i am having problems with this script the first part works ok but if i add another mysql_fetch_array it gives me an error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\phpbb3hacks\profile.php on line 61

 

anyways here is my code

 

<!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" />
<title>Untitled Document</title>
</head>

<body>
<h1> Viewing Profile For <?php $userid=$_GET['userid']; echo "$userid"; ?> </h1>
<br />
Deatils for <?php $userid=$_GET['userid']; echo "$userid"; ?><br />
<br />
<table width="50%" border="0" cellspacing="0" cellpadding="3" align="left" >
<tr>
<th align="left">Name</th>
<th align="left">E-Mail</th>
<th align="left">Website</th>
</tr>

<?php
include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$sql=mysql_query("SELECT * FROM users");

$result=mysql_fetch_array($sql);

$userid = $result['userid'];
$name = $result['name'];
$email = $result['email'];
$website = $result['website'];

echo "<td>$name</td>\n";
echo "<td>$email</td>\n";
echo "<td>$website</td>\n";

?>
</table>
<br />
<br />
<br />
<br />
Hacks Submmited By <?php $userid=$_GET['userid']; echo "$userid"; ?>
<br />
<table width="50%" border="0" cellspacing="0" cellpadding="3" align="left" >
<tr>
<th align="left">Hack Name</th>
<th align="left">Description</th>
</tr>

<?php
$sql2=mysql_query("SELECT * FROM hacks WHERE 'username'={$_GET['userid']}");

$result=mysql_fetch_array($sql2);

$userid = $result['userid'];
$hackname = $result['hackname'];
$description = $result['description'];


echo "<td>$hackname</td>\n";
echo "<td>$description</td>\n";


?>
</table>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/44393-multiple-mysql_fetch_array-problems/
Share on other sites

Use that or DIE(mysql_error()) after your mysql_query see why it is throwing an error. I am betting it is in the WHERE statement due to single quotes ( ' ) and not (  `  ). IE:

 

WHERE 'username'

 

SHOULD BE

 

WHERE `username`='".$_GET['userid']."'

 

Note single quotes around the inputed data.

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.