php - PDO update database -
hi i'm new php , pdo. trying update record in database depending on login_id variable have declared in sessions file (my session working fine).
i have following code update script. throwing errors execute statement.
"uncaught exception 'pdoexception' message 'sqlstate[hy093]: invalid parameter number: number of bound variables not match number of tokens' in /home/atlismap/public_html/bio.php:40 stack trace: #0 /home/atlismap/public_html/bio.php(40): pdostatement->execute() #1 {main}"
does know why?
require_once 'check.php'; $sql = "update users set username = :username, full_name = :full_name, country = :country, bio = :bio id = : $log_user_id"; $stmt = $dtb->prepare($sql); $stmt->bindparam(':full_name', $_post['full_name'], pdo::param_str); $stmt->bindparam(':country', $_post['country'], pdo::param_str); $stmt->bindparam(':bio', $_post['bio'], pdo::param_str); $stmt->execute();
you have set ':username' other params:
$stmt->bindparam(':username', $_post['username'], pdo::param_str);
and fix:
$sql = "update users set … id = : $log_user_id";
by:
$sql = "update users set … id = :id"; $stmt->bindparam(':id', $log_user_id, pdo::param_int);
pdo permits bind param ":param_name" use variable id can use param ":id" , bind it, or use "where id=$variable.
Comments
Post a Comment