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"];
}
?>
That error messages means that
$resultrespectivemysql_query()didn’t return a valid resource.Please try
mysql_query($query) or die(mysql_error());. By the way I don’t see amysql_connect()andmysql_select_db()!Warning:
Your code is very insecure (–>SQL injection)!
Please escape all data coming from
$_GETor$_POSTviamysql_real_escape_string()orintval(if it is an integer!).