關於Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result問題

來源:互聯網
上載者:User
剛學php
$con = mysql_connect("localhost","root","","PhysicalTest");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("PhysicalTest", $con);
mysql_query("SET NAMES 'gbk_chinese_ci'");

error_reporting(E_ALL ^ E_NOTICE);
if(isset($_COOKIE['student_id']))
{
$student_id=$_COOKIE['student_id'];
}

$result=mysql_query("SELECT * FROM 成績 WHERE 學號 ='$student_id'");

$row=mysql_fetch_array($result);
if(empty($row)) echo "";
else{
echo <<< HTML
...
標紅的那個為什麼會有warning, mysql_fetch_array(): supplied argument is not a valid MySQL result 。。。資料庫表格也沒有錯啊。。。求問怎麼回事。


回複討論(解決方案)

$result=mysql_query("SELECT * FROM 成績 WHERE 學號 ='$student_id'");
查詢失敗了
你可以用 echo mysql_error(); 看一下究竟是什麼錯

估計是中文表名和欄位名的問題

$result=mysql_query("SELECT * FROM 成績 WHERE 學號 ='$student_id'") or die(mysql_error());
看看有什麼錯誤

$result=mysql_query("SELECT * FROM 成績 WHERE 學號 ='$student_id'");
查詢失敗了
你可以用 echo mysql_error(); 看一下究竟是什麼錯

估計是中文表名和欄位名的問題


--------------------------------------------------------------------------------------
結果是這樣:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '��績 WHERE 學號 =''' at line 1
是不是因為表名、列名是中文?要改成英文?

你先這樣試試
$result=mysql_query("SELECT * FROM `成績` WHERE `學號` ='$student_id'");

但不是長久之計,你不願起英文名字,也可以用漢語拼音呀

你先這樣試試
$result=mysql_query("SELECT * FROM `成績` WHERE `學號` ='$student_id'");

但不是長久之計,你不願起英文名字,也可以用漢語拼音呀


下次不用中文了,多謝
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.