mercredi 6 mai 2015

WordPress Custom Database if statement and Update issues

I'm trying to update a custom database called wp_afterhours. Here is a look at what it holds. database snapshot

Is there a better way where I can use two option dropdowns, so the user can select one of three options for the primary contact, and one of three options of the secondary contact (with an if statement to compare the selections, to make sure the same isn't chosen for both). I want to be able to compare using php and to update the database with the primary_tech field set to one, for the primary, and the secondary_tech field set to 1 for the secondary. Of course, if there is a previous selection, it would need to be put to zero, as well. I have been trying this for a while now and have had no luck. Can someone help me find a decent solution? The comparison doesn't work at all, at this point. //update query $wpdb->query( " UPDATE $wpdb->wp_afterhours SET primary_tech = 1 WHERE id = $primary_selection; " ); $wpdb->query("UPDATE $wpdb->wp_afterhours SET secondary_tech = 1")

and this for the if statement `if the form is submitted if (isset($_POST['submit'])) {

//check to make sure both options chosen are not the same
if ($_POST['primary_'] === $_POST['secondary']) {
    $hasError = true;
    $hasErrorMessage = "Both Options cannot be the same.  Change one.";
} else {
    $hasError = false;
    $primary_contact = $_POST['primary_contact'];
    $secondary_contact = $_POST['secondary_contact'];
}

// retrieve the primary tech info

} `Please help!

Aucun commentaire:

Enregistrer un commentaire