Thursday, 6 October 2016

how to pass a id variable to a query in php/mysqli?

Can someone tell me how I can pass an ID to an UPDATE query in PHP/MySQL? Every time I select "ID #3" in the drop down box of a form, my update query always reads ID #1. I believe the problem is somewhere in the code below. I've been stuck with this for 2 days. I can't tell what I'm missing in my code. Your help is greatly appreciated.



        



Update Existing Customer
  • Customer ID:



  • First Name: Last Name:

  • Email Address:

  • Phone Number:

  • Street Number: Street Line 1:

  • Street Line 2 (Apt or Unit Number):

  • City: State: Zip:







  • Here is the updatecustomer.php file:



        //Turn on error reporting
    ini_set('display_errors', 'On');

    if(!($stmt = $mysqli->prepare("UPDATE customer SET fName=?, lName=?, email=?, phone_number=?, address_no=?, address_street1=?,
    address_street2=?, address_city=?, address_state=?, address_zip=? WHERE customer_id=?"))){
    echo "Prepare failed: " . $stmt->errno . " " . $stmt->error;
    }


    echo $_POST['customer_id'];

    if(!($stmt->bind_param("sssiissssii",$_POST['fName'],$_POST['lName'],$_POST['email'],$_POST['phone_number'], $_POST['address_no'],
    $_POST['address_street1'],$_POST['address_street2'],$_POST['address_city'],$_POST['address_state'], $_POST['address_zip'], $_POST['customer_id']))){
    echo "Bind failed: " . $stmt->errno . " " . $stmt->error;
    }
    if(!$stmt->execute()){
    echo "Execute failed: " . $stmt->errno . " " . $stmt->error;
    } else {

    echo "Updated " . $stmt->affected_rows . " rows to customer.";

    }


    $stmt->close();


    ?>

    No comments:

    Post a Comment

    c++ - Does curly brackets matter for empty constructor?

    Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...