Question

I'm working on making a receipt for my registration code and I keep getting this error:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in

<?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"];
}
?>
Was it helpful?

Solution

That error messages means that $result respective mysql_query() didn't return a valid resource.

Please try mysql_query($query) or die(mysql_error());. By the way I don't see a mysql_connect() and mysql_select_db()!

Warning:

Your code is very insecure (-->SQL injection)!

Please escape all data coming from $_GET or $_POST via mysql_real_escape_string() or intval (if it is an integer!).

OTHER TIPS

Replace this:

$result = mysql_query ($query);

With this and see what error happens:

$result = mysql_query ($query) or die(mysql_error());

You must first connect to your Database Server and select the database on which you wish to work.

<?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 */
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top