我正在为我的注册码制作收据,并且我一直收到此错误:
mysql_fetch_array()期望参数1是资源,在
中给出布尔值
<?php
// (2)gather details of CustomerID sent
$customerId = $_GET['CustomerID'] ;
// (3)create query
$query = "SELECT * FROM Customer WHERE CustomerID = $customerId";
// (4) Run the query on the customer table through the connection
$result = mysql_query ($query);
// (5) print message with ID of inserted record
if ($row = mysql_fetch_array($result))
{
print "The following Customer was added";
print "<br>Customer ID: " . $row["CustomerID"];
print "<br>First Name: " . $row["Firstnames"];
print "<br>Surname: " . $row["Surname"];
print "<br>User Name: " . $row["Username"];
print "<br>Email: " . $row["Email"];
print "<br>Password: " . $row["Password"];
}
?>
答案 0 :(得分:0)
替换它:
$result = mysql_query ($query);
有了这个,看看发生了什么错误:
$result = mysql_query ($query) or die(mysql_error());
答案 1 :(得分:0)
该错误消息表示$result
各自mysql_query()
未返回有效资源。
请尝试mysql_query($query) or die(mysql_error());
。顺便说一句,我看不到mysql_connect()
和mysql_select_db()
!
警告:强>
您的代码非常不安全( - &gt; SQL注入)!
请通过$_GET
或$_POST
(如果是整数!)来逃避来自mysql_real_escape_string()
或intval
的所有数据。
答案 2 :(得分:0)
首先必须连接到数据库服务器并选择要使用的数据库。
<?php
if ( isset($_GET['CustomerID']) )
{
$customerId = $_GET['CustomerID'] ;
$con = mysql_connect("your_db_address", "db_username", "db_password");
if(!$con)
{
echo "Unable to connect to DB: " . mysql_error();
exit;
}
$db = mysql_select_db("your_db_name");
if (!$db)
{
echo "Unable to select DB: " . mysql_error();
exit;
}
/* Rest of your code starting from $query */
}
?>