简体   繁体   中英

PDO Query Not Working

I've tested it, the SESSION ID is giving out a valid id, and so is all the other parameters. Help me.

$sql = 'UPDATE users SET firstname = :firstname, lastname = :lastname WHERE id = :id'; 
$records->bindParam(':id',$_SESSION['user_id']);

        $stmt = $conn->prepare($sql);
        list($firstname, $lastname) = explode(' ', $nn);

        $stmt->bindParam(':firstname', $firstname);
        $stmt->bindParam(':lastname', $lastname);

        if($stmt->execute()) {



        } else {

            die("An error adapted during changes.");

        }

I thought your query should be like this.

$sql = 'UPDATE users SET firstname = :firstname,      lastname = :lastname WHERE id = :id' ;
$stmt = $conn->prepare($sql);
list($firstname, $lastname) = explode(' ', $nn);
$stmt->bindParam(':id',$_SESSION['user_id']); 
$stmt->bindParam(':firstname', $firstname);
$stmt->bindParam(':lastname', $lastname); 
if($stmt->execute()) {



    } else {

        die("An error adapted during changes.");

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM