php - login form using session and pdo -
php - login form using session and pdo -
i have started convert old sql code pdo having difficulties in doing so, have tried convert login script pdo form, here conversion
<?php session_start(); // starting session if (isset($_post['submit'])) { seek { // define $email , $password $email = $_post['email']; $password = $_post['password']; //etablishing connection server $dbhost = "qwe.com"; $dbname = "qwe"; $dbuser = "qwe"; $dbpass = "qwe"; $conn = new pdo("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); $stmt = $conn->prepare("select * register where `email` = :email , `password` = :password "); $stmt->execute(array(':email' => $_post['email'],':password'=> $_post['password'])); $num=$stmt->fetchcolumn(); if($num > 0) { header("location:dashboard.php"); } else { header("location:login.php"); } } grab (exception $e) { echo 'caught exception: ', $e->getmessage(), "\n"; } } ?>
the page not getting redirected page, instead getting redirected blank page
your query fails prepare because have 2 where
in sql query.
select * register where where email
= :email , password
= :password
you should set connection throw errors:
$conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);
check values not submit
if (isset($_post['submit'], $_post['email'], $_post['password']))
full code:
<?php session_start(); // starting session if (isset($_post['submit'], $_post['email'], $_post['password'])) { seek { // define $email , $password $email = $_post['email']; $password = $_post['password']; //etablishing connection server $dbhost = "qwe.com"; $dbname = "qwe"; $dbuser = "qwe"; $dbpass = "qwe"; $conn = new pdo("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); $sql = "select * register `email` = :email , `password` = :password "; $stmt = $conn->prepare($sql); $stmt->execute(array(':email' => $_post['email'], ':password'=> $_post['password'])); $num=$stmt->rowcount(); if($num > 0){ header("location:dashboard.php"); } else{ header("location:login.php"); } }catch (exception $e) { echo 'caught exception: ', $e->getmessage(), "\n"; } } ?>
php mysql pdo
Comments
Post a Comment