I may be making a silly mistake, but I've been looking at it for ages and i cannot figure out what it is. So i was wondering if anyone can help!!! Please...
I have some data stored in PHP variables that are used to insert data to a mySQL db.
I have a customer table which automatically generates a custid number. So when I enter a new customer it is automatically given an id.
Now I need this custid, to be able to insert it into the next table. However for some reason when I query the customer table to obtain this custid, it returns nothing.
Here is my code:
if ( $referer[0] == URLLIST && $yesButton == 'Yes' ) {
if ( !($db = mysql_connect($host, $user, $passwd)) ) {
printError(sprintf("Error connecting to database from %s, by user %s", $host, $user));
} else {
mysql_select_db($dbName, $db);
$query1 = "INSERT INTO customer (Name, addr1, addr2, addr3, postcode, email, passwd, cardnum, expiry)" .
"VALUES('$Name', '$Add_1', '$Add_2', '$Add_3', '$P_code', '$Email', '$pword', '$Card', '$expiry')";
if ( !mysql_query($query1,$db) ) {
printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
} else {
echo ("Thank you for completing the registration form $Name <br /><br />\n");
}
//Now I want to find the custid that has been generated to put in the next table
//Query to find custid
$find = "select custid from customer where Name = $Name";
$answer = mysql_query($find,$db);
//Put custid into PHP variable $custid
$custid = $answer["custid"];
echo "Customer id is " . $custid;
$query2 = "INSERT INTO custord (custid, ortime, numdvd, carriage, orvalue)" .
"VALUES ('$custid', '', '$NoDVD', '$Tx', '$Total')";
if ( !mysql_query($query2,$db) ) {
printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
} else {
echo ("Thank you for making an order $Name <br /><br />\n");
}
mysql_close($db);
}
exit('</head><body></body></html>');
}
I can't figure out why $custid is empty!!!!!
Any solutions??
Thanks for your help
Reg
Gary