[英]how to compare the value in the same table in a different column
so i have a verification table consists of key_id, key_verification, confirm_key, and key_status 所以我有一个验证表,由key_id,key_verification,confirm_key和key_status组成
this is the sql process for client_verifycodez.php where i want to compare the value of key_verification and confirm_key if they are the same 这是client_verifycodez.php的sql进程,在这里我要比较key_verification和Confirm_key的值(如果它们相同)
the update sql is needed so that when client enter the key fro a form, it will enter into db as confirm_key. 需要更新sql,以便当客户端从表单输入密钥时,它将作为Confirm_key输入db。 so by that i want to compare the value of confirm_key with the already existing key_verification
所以我想将confirm_key的值与已经存在的key_verification进行比较
$sql1 = "UPDATE verification SET confirm_key = '".$confirm_key."' WHERE key_id ='".$id."'";
mysql_query($sql1);
$sql = ("SELECT * FROM verification WHERE key_verification = confirm_key");
$query = mysql_query($sql) or die ("Error: " . mysql_error());
$check = mysql_fetch_array($query);
if($check==true)
{
echo "<center>";
echo "Your key is invalid!";
echo "<br>";
echo "<a href=client_verifycodez.php>Back </a>";
echo "</center>";
}
else
{
header("Location: home.php");
}
so what i need is how do i compare so that when key_verification and confirm_key is equals, it will go to home.php or else alert. 所以我需要如何比较,以便当key_verification和Confirm_key相等时,它将转到home.php或发出警报。 i think i have the problem with the sql.
我认为我有SQL问题。
can anyone perhaps help me? 有人可以帮我吗? thank you
谢谢
You can't do like this, use sub-query, 您不能这样做,请使用子查询,
"SELECT * FROM verification WHERE key_id =". $id ." AND key_verification
= (SELECT confirm_key FROM verification WHERE key_id =". $id .")"
Note: Please, don't use mysql_*
functions in new code . 注意: 请不要在新代码中使用
mysql_*
函数 。 They are no longer maintained and are officially deprecated . 它们不再维护,已正式弃用 。 See the red box ?
看到红色框了吗? Learn about prepared statements instead, and use PDO , or MySQLi - this article will help you decide which.
而是了解准备好的语句 ,并使用PDO或MySQLi- 本文将帮助您确定哪一个。 If you choose PDO, here is a good tutorial .
如果您选择PDO, 这是一个很好的教程 。
The mysql_num_rows() function will return the number of existing rows count mysql_num_rows()函数将返回现有行数
please use mysqli extension always 请始终使用mysqli扩展名
<?php
$sql = ("SELECT * FROM verification WHERE key_verification = confirm_key");
$query = mysql_query($sql) or die ("Error: " . mysql_error());
//get the number of result rows
$num_rows = mysql_num_rows($query);
//get the details
$check = mysql_fetch_array($query);
if($query)
{
if($num_rows>0)
{
echo "<center>";
echo "Your key is invalid!";
echo "<br>";
echo "<a href=client_verifycodez.php>Back </a>";
echo "</center>";
}
else
{
header("Location: home.php");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.