<?php
include 'dbc.php';
?>
<?php session_start();
$id = $_SESSION['user_id'];
//$update = Reminder1;
// $rt1 = Reminder1;
// $mm1 = Reminder1;
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$data = mysql_query("SELECT reminder FROM users WHERE $id = id)")
or die(mysql_error());
if EXISTS (reminder == Reminder1)') {
echo("Update Your Pasword reset reminder page");
}
else {
echo("redirect to /home.php");
}
?>
任何人都可以帮助我解决为什么这会失败,会很好我一直在研究这一段时间,感觉就像我打砖墙大声笑。我仍然在测试所以回声将很快被编辑,因为它处于工作状态,所以忽略它们现在我把它全部留作了例子。
答案 0 :(得分:1)
Why is the MySQL extension (ext/mysql) discouraged from use?
<?php
session_start();
$id = $_SESSION['user_id'];
$DB = new PDO('mysql:dbname=database;host=localhost', 'user', 'pass');
$stmt = $DB->prepare('SELECT reminder FROM users WHERE id = ?');
$stmt->execute(array($id));
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result == 'Reminder1') {
echo 'Update Your Pasword reset reminder page';
} else {
header('Location: /home.php');
}
?>
另见:
答案 1 :(得分:0)
获取数据
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$data = mysql_query("SELECT reminder FROM users WHERE id='".$id."' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_assoc($data);
if($row['reminder'] == 'Reminder1') {
header("Location: /reset_password.php");
}
else {
header("Location: /home.php");
}
// but you should use PDO
$dbh = new PDO('mysql:host=localhost;dbname=database', 'user', 'pass');
$sth = $dbh->prepare("SELECT reminder FROM users WHERE id=:id LIMIT 1");
$sth->execute(array(':id' => $id));
$sth->setAttribute(PDO::FETCH_ASSOC);
$row = $sth->fetch();
if($row['reminder'] == 'Reminder1') {
header("Location: /reset_password.php");
}
else {
header("Location: /home.php");
}