php - UPDATE to database using PDO error -


i used pdo update values table using following method

form

<form role="form" method="post" action="submitupdate.php" autocomplete="off">    <input class="update" type="text" name="fullname"></li>    <input class="update" type="text" name="dob"></li>    <textarea style="width:740px;height:220px;" class="update" type="text" name="intrested"></textarea></li>    <textarea style="width:740px;height:220px;" class="update" type="text" name="description"></textarea></li> </form> 

processing

<?php  require('includes/config.php'); //if not logged in redirect login page if (!$user->is_logged_in()) {     header('location: login.php'); } //define page title $title = 'members page'; //include header template ?> <?php      try {      $username = $_session['username'];     $fullname = $_post['fullname'];     $dob = $_post['dob'];     $intrested = $_post['intrested'];     $description = $_post['description'];     $sql = "update `members`       set `fullname` = :firstname,        `dob` = :dob,        `intrested` = :intrested,        `description` = :description   `username` = :username";        $statement = $db->prepare($sql);     $statement->bindvalue(":username", $username);     $statement->bindvalue(":fullname", $fullname);     $statement->bindvalue(":dob", $dob);     $statement->bindvalue(":intrested", $intrested);     $statement->bindvalue(":description", $description);     $count = $statement->execute();      $db = null;        // disconnect } catch (pdoexception $e) {     echo $e->getmessage(); } 

am updating column using user name not id updat happen using username , user name called using session

i following error

sqlstate[hy093]: invalid parameter number: parameter not defined 

can me

you executing query before setting values. @ time of execution of query, values trying use not set yet, there not data replace placeholders.

this should work:

<?php  require('includes/config.php'); //if not logged in redirect login page if (!$user->is_logged_in()) {     header('location: login.php'); } //define page title $title = 'members page'; //include header template  try {      $username = $_session['username'];     $fullname = $_post['fullname'];     $dob = $_post['dob'];     $intrested = $_post['intrested'];     $description = $_post['description'];     $sql = "update `members`       set `fullname` = :fullname,        `dob` = :dob,        `inserted` = :inserted,        `description` = :description   `username` = :username";        $statement = $conn->prepare($sql);     $params = array(         ":username" => $username,         ":fullname" => $fullname,         ":dob" => $dob,         ":inserted" => $intrested,         ":description" => $description     );     $count = $statement->execute($params);      $conn = null;        // disconnect } catch (pdoexception $e) {     echo $e->getmessage(); } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -