09/10/2018, 18:27
PHP hiện tượng lạ ??
Em viết 1 đoạn php như sau để đọc mẩu tin :
nhưng khi chạy truyền tham số cho biến $id thì nó lại báo lỗi :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Em mong các cao thủ chỉ dùm .
<?php
$dbuser="hanguyen_chv"; //Database Username
$dbname="hanguyen_chv"; //Database Name
$dbpass="hvschools"; // Database Password
$c=mysql_connect("localhost","$dbuser","$dbpass");
mysql_select_db($dbname);
$todo="SELECT * FROM news where tid=$id";
$solution=mysql_query($todo);
while ($place = mysql_fetch_array($solution))
{
$text=$place["post"];
echo "$text";
}
?>
nhưng khi chạy truyền tham số cho biến $id thì nó lại báo lỗi :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Em mong các cao thủ chỉ dùm .
<?php
$dbuser="hanguyen_chv"; //Database Username
$dbname="hanguyen_chv"; //Database Name
$dbpass="hvschools"; // Database Password
$c=mysql_connect("localhost","$dbuser","$dbpass");
mysql_select_db($dbname);
$todo="SELECT * FROM news where tid=$id";
$solution=mysql_query($todo);
while ($place = mysql_fetch_array($solution))
{
$text=$place["post"];
echo "$text";
}
?>
Bài liên quan
tức là không tìm được bản ghi nào
$place=mysql_fetch_array($solution)) phải đổi thành
$place=mysql_fetch_array($solution,MYSQL_ASSOC));
SELECT * FROM news where tid=
Cũng có nghĩa là không thoả mãn điều kiện nào cả. Do đó kết quả trả về "Not Found" là đúng rồi!
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource cũng có thể hiểu như một cảnh báo rằng không tìm thấy kết quả nào thôi.