【发布时间】:2017-08-21 10:37:26
【问题描述】:
您好我正在尝试创建一个登录系统,我在后端的技能非常有限。我使用教程创建了一个数据库,意识到我在其他页面上的所有 php 都使用了 pdo,而本教程是 mysqli。
我已尝试修改此代码以尝试对其进行调整,但是我的尝试并未成功。
真的很厚颜无耻,但如果有人可以编辑代码以使用 PDO 将不胜感激 :)。
非常感谢
<?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 * FROM 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 are empty
if (empty($uid)) || empty($pwd)) {
header("location: ../index.php?login=empty");
exit();
}
} else {
$sql = "SELECT * FROM users WHERE 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 the password
$hashedPwdCheck = password_verify($pwd, $row['user_pdw']);
if ($hashedPwdCheck == false) {
header("location: ../index.php?login=error");
exit();
} elseif ($hashedPwdCheck == true) {
//Log in the 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();
}
?>
【问题讨论】:
-
“如果有人可以编辑代码以使用 PDO”这不是 Stack Overflow 的工作方式。我们不是来为您编写代码的。请使用tour 并阅读help center 中的主题。
标签: php mysql database mysqli pdo