【发布时间】:2012-05-10 14:10:15
【问题描述】:
当我尝试在之前的问题中发布时,我想知道如何从 php 中的 URL 和 mySQL 数据库获取数据,然后比较结果,如果它们相等,则运行一个事件。到目前为止,我有这段代码,但只要 URL 中有一个 id,它似乎无论如何都可以工作。它从不根据 mysql 数据库中的 id 检查它。有什么想法吗?
代码如下:
<?php
$random = uniqid();
if ($id = $_GET['id']) {
$dbhandle = mysql_connect('host', 'user', 'password')
or die("Unable to connect to MySQL");
$selected = mysql_select_db('a6675286_main',$dbhandle)
or die("Could not select database");
$sql = "SELECT completed FROM authentication WHERE username='admin'";
$id2 = mysql_query($sql);
}
if ($id = $id2) {
mysql_query("UPDATE authentication SET completed = $random WHERE username = 'admin'");
include 'sendmail.php';
echo "You win";
}
else {
header('Location: http://www.websites.com/');
}
?>
【问题讨论】:
-
$set_me = 'I set You';$equal == '';$identical === ''; -
请停止使用古老的
mysql_*函数编写新代码。它们不再维护,社区已经开始 deprecation process 。相反,您应该了解prepared statements 并使用PDO 或MySQLi。如果您无法决定,this article 将帮助您选择。如果你想学习,here is a good PDO-related tutorial. -
我不知道有更新的函数,我总是使用你的“古老”mysql 函数。但真的感谢您的更新,因为该代码必须至少有 70 年的历史。