mysql - Converting MYSQLI TO PDO in PHP -


hello trying create login system, , skills in back-end extremely limited. used tutorial create database realising php on other pages used pdo tutorial mysqli.

i have tried tinkering code try , adapt it, tries have not been successful.

really cheeky appreciated if edit code work pdo :).

many thanks

<?php  try {    $handler = new pdo('mysql:host=127.0.0.1;dbname=loginsytem', 'root', '');    $handler->setattribute(pdo::attr_errmode, pdo::errmode_exception);  } catch(pdoexception $e){    echo $e->getname();    die();  }   session_start();   $query = $handler->query('select * users');   if (isset($_post['submit'])) {     incude_'dbh.inc.php';     $uid = pdo::quote($conn, $_post['uid']);    $pwd = pdo::quote($conn, $_post['pwd']);     //error handlers    //check if inputs empty     if (empty($uid)) || empty($pwd)) {      header("location: ../index.php?login=empty");      exit();    }  }   else {      $sql = "select * users user_uid='$uid'";      $result = mysqli_query($conn, $sql);      $resultcheck = mysqli_num_rows($result);      if ($resultcheck < 1) {        header("location: ../index.php?login=error");        exit();      } else {        if ($row = mysqli_fetch_assoc($result)) {          //de-hashing password          $hashedpwdcheck = password_verify($pwd, $row['user_pdw']);          if ($hashedpwdcheck == false) {            header("location: ../index.php?login=error");            exit();           } elseif ($hashedpwdcheck == true) {            //log in user here            $_session['u_id'] = $row['user_id'];            $_session['u_uid'] = $row['user_uid'];            header("location: ../index.php?login=success");            exit();          }        }      }    }     else {    header("location: ../index.php?login=error");    exit();  }    ?> 

here go.. notice changes comparing code.. learn pdo mysql, refer tutorial http://wiki.hashphp.org/pdo_tutorial_for_mysql_developers

<?php  try {    $handler = new pdo('mysql:host=127.0.0.1;dbname=loginsytem', 'root', '');    $handler->setattribute(pdo::attr_errmode, pdo::errmode_exception);  } catch(pdoexception $e){    echo $e->getname();    die();  }   session_start();   //$query = $handler->query('select * users');   if (isset($_post['submit'])) {     //error handlers    //check if inputs empty     if (empty($uid)) || empty($pwd)) {      header("location: ../index.php?login=empty");      exit();    }  }   else {       $stmt = $db->prepare("select * users user_uid=:uid");      $stmt->bindparam(':uid', $uid, pdo::param_str);       if ($stmt->execute()) {        header("location: ../index.php?login=error");        exit();      } else {        if ($row = $stmt->fetch(pdo::fetch_assoc)) {          //de-hashing password          $hashedpwdcheck = password_verify($pwd, $row['user_pdw']);          if ($hashedpwdcheck == false) {            header("location: ../index.php?login=error");            exit();           } elseif ($hashedpwdcheck == true) {            //log in user here            $_session['u_id'] = $row['user_id'];            $_session['u_uid'] = $row['user_uid'];            header("location: ../index.php?login=success");            exit();          }        }      }    }     else {    header("location: ../index.php?login=error");    exit();  }    ?> 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -