gpt4 book ai didi

php - 警告 : mysql_fetch_array() expects parameter 1 to be resource, 给出 bool 值

转载 作者:行者123 更新时间:2023-11-30 23:59:23 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:




9年前关闭。




Possible Duplicate:
PHP: Warning: sort() expects parameter 1 to be array, resource given



这是我的代码:我看不到任何应该导致这种情况的...想法?

警告:mysql_fetch_array() 期望参数 1 是资源,给定的 bool 值。
 <?php

include_once "mysql_connect.php";

if ($_POST['parse_var'] == "contactform"){

if(is_array($categories)) $whereCond = "in '".implode(",",$categories); else
$wherecond = "= ".$categories;

$dropdownValue = $_POST['dropdown'];

$dropdownValue = mysql_real_escape_string($dropdownValue);
$dropdownValue = eregi_replace("`", "", $dropdownValue);


$searchField= $_POST['searchinput'];
$searchField = mysql_real_escape_string($searchField);
$searchField = eregi_replace("`", "", $searchField);


if ($dropdownValue == "phone"){
$sql = mysql_query("SELECT * FROM pcparts WHERE phone='$searchField'");


while($row1 = mysql_fetch_array($sql)){


$arrayuserinfo[] = array(

'phone' => $row1["phone"],
'name' => $row1["name"],
'city' => $row1["city"],
'state' => $row1["state"],
'address' => $row1["address"],
'zip' => $row1["zip"],
);
};
for($i=0;$i < count($arrayuserinfo);$i++){

$phone = $arrayuserinfo[$i]["phone"];
$name = $arrayuserinfo[$i]["name"];
$city = $arrayuserinfo[$i]["city"];
$state = $arrayuserinfo[$i]["state"];
$address = $arrayuserinfo[$i]["address"];
$zip = $arrayuserinfo[$i]["zip"];
echo"<table width='400' border='1' cellpadding='3'>
<tr>
<td>phone</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>state</td>
<td>zip</td>
</tr>
<tr>
<td>$phone</td>
<td>$name</td>
<td>$address</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
</tr>
</table><br />
";
}
}

else if ($dropdownValue == "name"){
$sql = mysql_query("SELECT * FROM pcparts WHERE name='$searchField'");


while($row1 = mysql_fetch_array($sql)){

$arrayuserinfo[] = array(

'phone' => $row1["phone"],
'name' => $row1["name"],
'city' => $row1["city"],
'state' => $row1["state"],
'address' => $row1["address"],
'zip' => $row1["zip"],
);
};

for($i=0;$i < count($arrayuserinfo);$i++){

$phone = $arrayuserinfo[$i]["phone"];
$name = $arrayuserinfo[$i]["name"];
$city = $arrayuserinfo[$i]["city"];
$state = $arrayuserinfo[$i]["state"];
$address = $arrayuserinfo[$i]["address"];
$zip = $arrayuserinfo[$i]["zip"];

echo"<table width='400' border='1' cellpadding='3'>
<tr>
<td>phone</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>state</td>
<td>zip</td>
</tr>
<tr>
<td>$phone</td>
<td>$name</td>
<td>$address</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
</tr>
</table><br />
";
}
}

else if ($dropdownValue == "city"){
$sql = mysql_query("SELECT * FROM pcparts WHERE city='$searchField'");


while($row1 = mysql_fetch_array($sql)){

$arrayuserinfo[] = array(

'phone' => $row1["phone"],
'name' => $row1["name"],
'city' => $row1["city"],
'state' => $row1["state"],
'address' => $row1["address"],
'zip' => $row1["zip"],
);
};

for($i=0;$i < count($arrayuserinfo);$i++){

$phone = $arrayuserinfo[$i]["phone"];
$name = $arrayuserinfo[$i]["name"];
$city = $arrayuserinfo[$i]["city"];
$state = $arrayuserinfo[$i]["state"];
$address = $arrayuserinfo[$i]["address"];
$zip = $arrayuserinfo[$i]["zip"];

echo"<table width='400' border='1' cellpadding='3'>
<tr>
<td>phone</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>state</td>
<td>zip</td>
</tr>
<tr>
<td>$phone</td>
<td>$name</td>
<td>$address</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
</tr>
</table><br />
";
}
}

}
?>




<html>
<body>
<h2>Customers Database Search</h2>

<form action="file1.php" method="POST">
<input type='hidden' name='parse_var' value='contactform'>
Search fields:
<select name="dropdown" id="dropdown" >
<option value="<?php print "$dropdownValue"; ?>"><?php print "$dropdownValue"; ?></option>
<option value="phone">phone</option>
<option value="name">name</option>
<option value="city">city</option>
</select>
Search item:<input type="text" name='searchinput' id="searchinput" value="
<?php print "$searchField"; ?>" size='20'><br><br>
<input type="submit" name="button" id="button" value="Search" />
</form>
<br />
<br />
</body>
</html>

mysql_connect:
   <?php

$db_host = "localhost";
$db_username = "user";

$db_pass = "test1234";

$db_name = "pcparts";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("$db_name") or die ("No database");

?>

如果你发现我需要添加的东西,你能告诉我具体放在哪里吗?

最佳答案

您的查询失败,您忘记使用 mysql_error() 找出原因。

关于php - 警告 : mysql_fetch_array() expects parameter 1 to be resource, 给出 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6723876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com