0

我试图从 elective_mgmt 数据库的优先级表中获取数据。源代码如下:

<?php
    $connect = mysql_connect("localhost","root","");
    mysql_select_db("elective_mgmt",$connect);
    $result = mysql_query($con,"SELECT * FROM priority");
        echo "<table border='1'>
`<tr>
<th>Name</th>
<th>Roll</th>
<th>Email</th>
<th>Priorityone</th>
<th>Prioritytwo</th>
<th>Prioritythree</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Name'] . "</td>";
  echo "<td>" . $row['Roll'] . "</td>";
  echo "<td>" . $row['Email']. "</td>";
  echo "<td>" . $row['Priorityone']."</td>";
  echo "<td" . $row['Prioritytwo']."</td>";
  echo "<td" . $row['Prioritythree']."</td>"; 
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

 ?>

当我运行它时,它显示如下:

Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\Elective_management\admin_view.php on line 5

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 15
Name    Roll    Email   Priorityone Prioritytwo Prioritythree

Warning: mysql_close() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 28
?>

我没有任何想法。请帮我。

4

4 回答 4

0

您的参数顺序mysql_query不正确。首先是查询,然后是连接。

mysql_query("SELECT * FROM priority", $connect);
于 2013-07-11T06:05:41.917 回答
0

你给了错误的连接。应该看起来像这样

 $result = mysql_query("SELECT * FROM priority",$connect );
于 2013-07-11T06:07:02.793 回答
0

你不应该需要连接变量,因为你刚刚连接。你应该可以输入

$result = mysql_query("SELECT * FROM priority");

让它工作得很好

于 2013-07-11T06:08:37.253 回答
0

1 -

mysql_close($con);

在这里你没有 $con 变量,所以它是空的,为什么会出现这个错误

Warning: mysql_close() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 28 

修复:更改

mysql_close($con);

mysql_close($connect);

2 -

$row = mysql_fetch_array($result)`

在这里你指向它$result并且$result你有$con = Null所以这个错误出现

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 15

使固定 :

当您修复第三步时将修复


3 -

$result = mysql_query($con,"SELECT * FROM priority");

再次在这里,您将第二个参数作为字符串,它不应该是字符串,因此会出现此错误

Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\Elective_management\admin_view.php on line 5

使固定 :

修复:更改

mysql_query($con,"SELECT * FROM priority");

mysql_query("SELECT * FROM priority",$connect)

PS:如果您刚刚开始在这个项目中编码,
请考虑将您的语法从MySql_*更改PDO 语法

于 2013-07-11T06:55:19.557 回答