php - Uncaught exception 'PDOException' error in my pdo -
after running code got kind of error, can help me prepare please. error starts after putting code filter if email duplicate or not in database.
here error got:
<?php $host = "localhost"; $user = "root"; $pass = ""; $db = "test"; $dbc = new pdo("mysql:host=" . $host . ";dbname=" . $db, $user, $pass); $dbc->setattribute(pdo::attr_errmode, pdo::errmode_exception); $name = @$_post['name']; $age = @$_post['age']; $address = @$_post['address']; $gender = @$_post['gender']; $email = @$_post['email']; $dupesql = "select * students email = :email "; $dupesql = $dbc->prepare($dupesql); $dupesql->bindparam(':name', $email); $dupesql->execute(); $num_rows = $dupesql->rowcount(); if($num_rows === 0) { echo "1"; $q = "insert students(name, age, address, gender, email ) values(:name, :age, :address, :gender, :email)"; $query = $dbc->prepare($q); $query->bindparam(':name', $name); $query->bindparam(':age', $age); $query->bindparam(':address', $address); $query->bindparam(':gender', $gender); $query->bindparam(':email', $email); $results = $query->execute(); }else{ echo "0"; exit; } ?>
well facing error because using wrong parameter in query.
$dupesql->bindparam(':name', $email); :name doesn't exists should :email.
php mysql sql database pdo
No comments:
Post a Comment