mercredi 4 avril 2018

PHP IF Statement Variable Is Not Defined [on hold]

I have a problem. I don't know why, but PHP says variable is undefined when echoed out.

Here it is:

if(empty($name)) {
    $name_err = "Name cannot be empty";
}else {
    $sql = 'UPDATE users SET name = :name WHERE id = :id';
    $stmt = $pdo->prepare($sql);
    $stmt->execute(['name' => $name, 'id' => $_SESSION['id']]);
}    

I echo out the $name_err variable and it says undefined. Although the statement works fine.

Aucun commentaire:

Enregistrer un commentaire