Good afternoon!
I have spent approximately 15 hours researching this, and tried every solution I could find, and I still don’t know what I’m doing wrong. Initially, I was getting SQL errors and blank pages, and empty forms…but I’ve fixed all of that. So, on to the problem that has been plaguing me for what seems like forever!
I have a function process_form($Email, $EmailOriginal). I want it to compare the values, and if it was originally empty, insert the value into the database. If the form field originally had data, it should update the database to reflect the new value. Unfortunately, all it does is go through the FIRST “if” statement and adds the data to the database whether the original value was blank or not. Here’s the function code:
[code=php]function process_form($Email, $EmailOriginal)
{
$tempEmail = $Email;
$tempOriginal = $EmailOriginal;
$tempRecipient = $RecipientEmail;
if (empty($tempOriginal))
{
$sql = “insert into NewOrderEmailNotification (RecipientEmail) values (‘$tempEmail’)”;
if (!mysql_query($sql))
{
die(‘Error: A’ . mysqli_error());
}
echo “1 record added”;
}
else if ($tempOriginal != $tempEmail)
{
$sql = “update NewOrderEmailNotification set ‘RecipientEmail’ to ‘$tempEmail’ where ‘RecipientID’ = 1”;
if (!mysql_query($sql))
{
die(‘Error: B’ . mysqli_error());
}
echo “Email successfully updated.”;
}
$tempRecipient = $tempEmail;
return $tempRecipient;
}
I have tried using “if ($tempOriginal != “”)”, “if ($tempOriginal != NULL)”, “if (is_null($tempOriginal))” and none of them have worked either.
Can anyone tell me why the function is always going into the first “if” statement, even though the variable has a value????
TIA!!