數據庫連接是正確的,但我得到一個錯誤說我的MySQL數據庫搜索代碼有什麼問題?
Warning:
mysql_fetch_array(): supplied argument is not a valid MySQL result on line 31
<?php
$hostname = "localhost";
$username = "user";
$password = "pass";
$usertable = "products";
$dbName = "test_prods";
$s = $_GET["s"];
$name = $row["product_name"];
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db("$dbName") or die("Unable to select database");
//error message (not found message)
$XX = "No Products Found";
$query = mysql_query("SELECT * FROM $usertable WHERE $s LIKE '$name'");
while ($row = mysql_fetch_array($query))
{
$variable1=$row["row_name1"];
$variable2=$row["row_name2"];
$variable3=$row["row_name3"];
print ("this is for $variable1, and this print the $variable2 end so on...");
}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>
你可以在調用'mysql_query'後查看'mysql_error'來查看是否有任何問題運行你的查詢。 –
'$ name = $ row [「product_name」];'---請解釋這一行 – zerkms
請注意,舊的mysql_%函數將被停用。這意味着您的代碼在PHP升級時可能會停止工作。對於新項目,您應該按照[PHP文檔中推薦的](http://www.php.net/manual/en/mysqlinfo.api.choosing.php)切換到mysqli擴展。 –