Tuesday, 15 July 2014

php - How to put a condition in my pdo code -



php - How to put a condition in my pdo code -

i want when user registered pdo have status if successful or not.

my problem how set if else status in pdo if user successful or not in registering account.

<?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']; $imagename = @$_files['image']['name']; $q = "insert students(name, age, address, gender, imagename ) values(:name, :age, :address, :gender, :image)"; $query = $dbc->prepare($q); $query->bindparam(':name', $name); $query->bindparam(':age', $age); $query->bindparam(':address', $address); $query->bindparam(':gender', $gender); $query->bindparam(':image', $imagename); $results = $query->execute(); ?>

my problem how set if else status in pdo if user successful or not in registering account.

pdostatement::execute() returns boolean true or false depending on result.

you should able check $results results...

echo $results ? 'user registered' : 'error registering user!';

php mysql pdo

No comments:

Post a Comment