I've written some code, it might not even run, not tried yet. But I've written it all with if else pairs where needed. I can't think of a better way of writing it. Is there a better way that's obvious to you?
The code is going to go into the head of the script and intercept the building of the page if a form with the field "email_notification" has been submitted. If so, it does it's thing, checking if they've entered an email address, and if the item they're subscribing to exists, then adds them, giving error status messages with each else statement. Eventually, it'll redirect to another page with the result of what's happened and kill execution of the rest of the script.
Thanks.
if (isset($_POST['email_notification'])) {
if (!empty($_POST['software_id'])) {
if (!empty($_POST['email_address'])) {
if ($result = mysql_query("SELECT shortname, fullname FROM soft_data WHERE shortname = '{$_POST['software_id']}'")) {
$fullname = mysql_fetch_array($result);
if (false !== mysql_query("INSERT INTO email_subs(soft_name, email_address) VALUES('{$_POST['software_id']}', '{$_POST['email_address']}')")) {
$status = "Your email address will be notified when " . $fullname['fullname'];
}
} else {
$status = "Software ID not found.";
}
} else {
$status = "No email address entered.";
}
} else {
$status = "No software ID entered.";
}
header("Location: http://example.com/subscription/?status=$status");
die();
}