php - Why won't my prepared statement function properly? -
i have ajax call affiliated php handler has prepared statement in it.
and won't work. no error caught.
it stopped working when changed deprecated mysql_real_escape pdo prepared statememt.
here code :
$create_pdo=new pdo("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); $statement=$create_pdo->prepare("insert registry (fname, lname, email, password, age, sex, city, timereg, frcode) values (:fname_received, :lname_received, :email_received, :password_received, :dob_received, :sex_received, :city_received, :timepassreg, :frcode)"); $statement->bindparam(':fname_received', $fname_received); $statement->bindparam(':lname_received', $lname_received); $statement->bindparam(':email_received', $email_received); $statement->bindparam(':password_received', $password_received); $statement->bindparam(':dob_received', $dob_received); $statement->bindparam(':sex_received', $sex_received); $statement->bindparam(':city_received', $city_received); $statement->bindparam(':timepassreg', $timepassreg); $statement->bindparam(':frcode', $frcode); $statement_executed=$statement->execute(); if ($statement_executed){ $messagetosend="<font size=\"2\" color=\"#347c17\" face=\"tahoma\"> <strong>Приветствуем нового пользователя проекта 'Фаворит'!</strong></font>,<br><font size=\"2\" color=\"#1f2320\" face=\"tahoma\">Для того, чтобы начать пользоваться нашим сайтом, вам нужно будет ввести авторизационный код.<br>Ваш авторизационный код: <font size=\"2\" color=\"#336699\" face=\"tahoma\"><strong>".$frcode."</strong></font><br>Этот процесс проводится в целях борьбы со спамом и его предотвращения.<br>С уважением,<br>Проект 'Фаворит'.</font>"; $mailheader='mime-version: 1.0' . "\r\n" . 'content-type: text/html; charset=utf-8' . "\r\n"; $mailheader.="x-mailer: php \r\n"; $mailheader.="from: Фаворит <passwordreminder@favorit.kz>"; mail($email_received,"Авторизация на проекте 'Фаворит'",$messagetosend,$mailheader); $array_to_json=array("database_input" => "true","mail_sent" => "true"); echo json_encode($array_to_json); }
how can fix ?
and won't work. no error caught.
to display query errors, need set error mode attribute pdo::attr_errmode. able see pdo errors same way other php errors
$create_pdo=new pdo("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); $create_pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception); $statement=$create_pdo->prepare('insert registry (fname, lname, email, password, age, sex, city, timereg, frcode) values (?, ?, ?, ?, ?, ?, ?, ?, ?)'); $statement_executed = $statement->execute(array($fname_received, $lname_received, $email_received, $password_received, $dob_received, $sex_received, $city_received, $timepassreg, $frcode));
Comments
Post a Comment