When I add a customer the record is added to the db, but this error is displayed:
Error in query:SELECT * FROM customer WHERE CustomerID = . You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Any pointers/solutions greatly appreciated
The code for the addcustomer page:
Code: Select all
<?php
include "connection.php"
?>
<?php
$newFirstname = $_POST['firstname'];
$newSurname = $_POST['surname'];
$newUsername = $_POST['username'];
$newEmail = $_POST['email'];
$newPassword = $_POST['password'];
$query = "INSERT INTO customer (Firstnames, Surname, Username, Email, Password) VALUES ('$newFirstname', '$newSurname', '$newUsername', '$newEmail', '$newPassword')";
$result = mysql_query($query) or die ("Error in query:$query.
".mysql_error());
// (5) print message with ID of inserted record
header("Location: userReceipt.php?"."CustomerID=". mysql_insert_id($connection));
mysql_close($connection);
?>Code: Select all
<?php
include "connection.php"
?>
<?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) or die ("Error in query:$query.
".mysql_error());
// (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"];
}
// close connection
mysql_close($connection);
?>