1

我正在为我的注册码制作收据,但我不断收到此错误:

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"];
}
?>
4

3 回答 3

0

替换这个:

$result = mysql_query ($query);

有了这个,看看会发生什么错误:

$result = mysql_query ($query) or die(mysql_error());
于 2011-11-23T13:43:03.260 回答
0

该错误消息意味着$result各自mysql_query()没有返回有效资源。

请尝试mysql_query($query) or die(mysql_error());。顺便说一句,我没有看到mysql_connect()and mysql_select_db()

警告:

您的代码非常不安全(-->SQL 注入)!

请转义来自$_GET$_POST通过mysql_real_escape_string()or的所有数据intval(如果它是整数!)。

于 2011-11-23T13:43:51.310 回答
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 */
}
?>
于 2011-11-23T13:45:54.703 回答