0

I've tried to do this, but I just can't find the error. It worked before where I just had "name, email, mobile" when I add "password" it stops working...

I don't know what to do for it to work properly as it worked before, please help

if ( !empty($_POST)) {
    // keep track validation errors
    $nameError = null;
    $emailError = null;
    $mobileError = null;
    $passwordError = null;
    // keep track post values
    $name = $_POST['name'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $password = $_POST['mobile'];

    // validate input
    $valid = true;
    if (empty($name)) {
        $nameError = 'Please enter Name';
        $valid = false;
    }

    if (empty($email)) {
        $emailError = 'Please enter Email Address';
        $valid = false;
    }

    if (empty($mobile)) {
        $mobileError = 'Please enter Mobile Number';
        $valid = false;
    }

    if (empty($password)) {
        $passwordError = 'Please enter Password Number';
        $valid = false;
    }
    // update data
    if ($valid) {
        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    //ERROR IS HERE    $sql = "UPDATE customers  set name = ?, email = ?, mobile = ?, password =?, WHERE id = ?";
        $q = $pdo->prepare($sql);
        $q->execute(array($name,$email,$mobile,$password,'ADD',$id));
        Database::disconnect();
        header("Location: index.php");
    }
} else {
    $pdo = Database::connect();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "SELECT * FROM customers where id = ?";
    $q = $pdo->prepare($sql);
    $q->execute(array($id));
    $data = $q->fetch(PDO::FETCH_ASSOC);
    $name = $data['name'];
    $email = $data['email'];
    $mobile = $data['mobile'];
    $password = $data['password'];
    Database::disconnect();
}

?>

4
  • 2
    password =?, WHERE id remove the comma. Check for mysqli errors when things fail to get more information on why things fail. Commented May 23, 2018 at 12:43
  • What does "work" mean? (i.e., what are you trying to do that is failing?) Also, what was the error you are seeing? Lastly, I'd recommend updating the formatting so all of your code is in a code block for readability (including the last ?>). Commented May 23, 2018 at 12:52
  • aynber thanks a lot, it worked!!!! Commented May 23, 2018 at 13:01
  • Don't store plain text passwords. Commented May 23, 2018 at 13:04

2 Answers 2

1

you need to change $password = $_POST['mobile']; to $password = $_POST['password'];

Sign up to request clarification or add additional context in comments.

1 Comment

While this would cause bad data going into the database, it would not stop the update from working as the OP claims.
0

Hi seems like you have a syntax error,

unexpected comma

//ERROR IS HERE    $sql = "UPDATE customers  set name = ?, email = ?, mobile = ?, password =?, WHERE id = ?";// remove comma prior to WHERE

try like below,

  $sql = "UPDATE customers  set name = ?, email = ?, mobile = ?, password =? WHERE id = ?";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.