I have a routine that will add user data to a db field.
If the user returns to the page, they can re-enter the data (if they wish). The old data is deleted and the new data is written to the db in its place.
The only criteria for this is the session value.
If the session value is present in the table, $numrows should be set to 1 and the delete and rewrite section is performed. Otherwise, it simply writes the data to the db.
The problem is that $numrows is always empty so the function always writes new data to the db without deleting the old values.
Can anyone see the problem
function add_customer($cart_id,$first_name, $last_name, $addr1, $addr2, $addr3, $addr4, $addr5, $pcode, $cntry, $email, $message, $ship) {
mysql_select_db("orderlog") or die("Unable to select database");
$query = "SELECT session FROM orderlog WHERE session='".$cart_id."'";
$numresults = mysql_query($query);
$numrows=mysql_num_rows($numresults);
if ($numrows==0){
mysql_select_db("orderlog") or die("Unable to select database");
$query = "INSERT INTO orderlog (session, first_name, last_name, addr1, addr2, addr3, addr4, addr5, pcode, cntry, email, message, ship) VALUES ('$cart_id', '$first_name', '$last_name', '$addr1', '$addr2', '$addr3', '$addr4', '$addr5', '$pcode', '$cntry', '$email', '$message', '$ship') ";
mysql_query($query);
}
else {
mysql_select_db("orderlog") or die("Unable to select database");
$query = "DELETE FROM orderlog WHERE session='".$cart_id."' ";
mysql_query($query);
$query = "INSERT INTO orderlog (session, first_name, last_name, addr1, addr2, addr3, addr4, addr5, pcode, cntry, email, message, ship) VALUES ('$cart_id', '$first_name', '$last_name', '$addr1', '$addr2', '$addr3', '$addr4', '$addr5', '$pcode', '$cntry', '$email', '$message', '$ship') ";
mysql_query($query);
}}
[code=php]