Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

php - Getting "supplied argument is not a valid MySQL result resource" when calling mysql_fetch_array()

I keep getting the same mysql error code but I dont know how to correct it.

Error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /websites/123reg/LinuxPackage22/we/ez/y_/weezy.co.uk/public_html/search.php on line 29

I have marked out line 29 on the code below.

What does this mean?

Thanks

<?php
// Change the fields below as per the requirements
$db_host="";
$db_username="";
$db_password="";
$db_name="";
$db_tb_name="data";
$db_tb_atr_name="name";
$db_tb_atr_name="email";
$db_tb_atr_name="location";


//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen

mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");

$query=mysql_real_escape_string($_GET['query']);

$query_for_result=mysql_query("

SELECT name, email, location

FROM data WHERE 

$db_tb_atr_name like '%".$query."%'");
echo "<h2>Search Results</h2><ol>";
while ($row = mysql_fetch_array($result))  <<<<<<<<<<<<<<< LINE 29 
{
echo "<li>";
echo substr($row["name"], $row["email"], $row["location"]);
echo "</li><hr/>";
}
echo "</ol>";

mysql_close();
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
while ($row = mysql_fetch_array($result)) 

Where have you set $result to anything?

You probably meant

while ($row = mysql_fetch_array($query_for_result))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...