0

Hi, I'm new to PHP.If i execute this code. It shows the warning as

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in c:\wamp\www\login_action.php on line 15
Name Address Telephone company"

I don't know how to solve this.

<?php
include 'connection.php';
$uname = $_REQUEST['uname'];//extract($_POST); $uname
$pword = $_REQUEST['pword'];
?>
<table cellpadding=0 cellspacing=0 border=0 width='50%' id='table'>
<tr>
<td> Name</td>
<td> Address</td>
<td> Telephone</td>
<td> company</td>
</tr>
<?php
$result = mysql_query("SELECT * FROM admin WHERE name ='shyloo'");
while($rs = mysql_fetch_assoc($result))
{
	echo "<tr>";
	echo "<td>";
	echo $rs['name'];
	echo "</td>";
	echo "<td>".$rs['address']."</td>";
	echo "<td>".$rs['tele']."</td>";
	echo "<td>".$rs['comp']."</td>";
}
?>

Edited by Shyloo: n/a

5
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rajabhaskar525
0

Don't know where exactly the issue is, but that while statement scares me.
The error means that there is something wrong with the query result.
you might also try just setting $rs outside the the while and doing a var_dump($rs) just to see what's there. Maybe the problem is all the way back at the connect.
The while statement is not correct, that will be your next problem.
I find them problematic and I try to avoid using them.

0

It means your query is failing to execute by some means and there's nothing to fetch at line15.
Try to echo the query and post it here. Directly execute it in the mysql, and post if any error, though it seems to be a simple query,there might be issue for column name or table name not matching

0

You should indeed check if there is a result before the while to catch this, like so:

$result = mysql_query("SELECT * FROM admin WHERE name ='shyloo'");
if ($result) {
  while($rs = mysql_fetch_assoc($result))
  {
	echo "<tr>";
	echo "<td>";
	echo $rs['name'];
	echo "</td>";
	echo "<td>".$rs['address']."</td>";
	echo "<td>".$rs['tele']."</td>";
	echo "<td>".$rs['comp']."</td>";
  }
}
else {
  // query error
  die (mysql_error());
}

If the query returns zero rows, there is still a resource, although empty, and the while will terminate directly.

Edited by pritaeas: n/a

0

check

$result = mysql_query("SELECT * FROM admin WHERE name ='shyloo'");
echo $result;exit;

. is it excute correctly . if results is lessthen zero your query is wrong.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.