1
    <?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");
}


?>

任何人都可以帮助我解决为什么会失败,会很棒,我已经为此工作了一段时间,感觉就像我正在打砖墙哈哈。我仍在测试中,所以 to echos 将在它处于工作状态时立即进行编辑,所以现在忽略它们行,我把它都留在了例子中。

4

2 回答 2

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');
}
?>

另见:

于 2012-08-18T11:50:33.393 回答
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");
}
于 2012-08-18T11:44:11.680 回答