如果 Pin 字段值与用户输入引脚相同,我想更新 mysql 表引脚。在这种情况下,我想在选择查询返回 true 后更新 appid 表中的 appid 字段。
<?php
If(isset($_POST['login'])){
$Pin=$_GET['pin'];
$ID =$_POST['ID'];
if($Pin!=''){
$result = mysql_query("SELECT * FROM pin WHERE Pin = '$Pin'");
$test = mysql_fetch_array($result);
mysql_query("UPDATE pin SET appid ='$num' WHERE Pin= '$Pin'")
or die(mysql_error());
header("location:compet_applicant.php");
}
}
?>
我认为您应该再添加一个field
,例如:先number_update
到您的pin
表中。默认值为 0
第一次更新,它将具有1
的值,您可以检查该值,如果是1
,会提醒ID Already in Use, Pls login
。如果是0
,则允许更新
$result = mysql_query("SELECT * FROM pin WHERE Pin = '$Pin'");
$test = array();
while ($row = mysql_fetch_array($result)) {
$test[] = array_map('utf8_encode', $row);
}
if($test["number_update"] == 1) { //Checking already updated
//Notify user that they have already updated
} else {
mysql_query("UPDATE pin SET appid ='$num' WHERE Pin= '$Pin'")
or die(mysql_error());
}
应该有一个记录表每次更新的日志表。如果找到记录,则系统应阻止对该特定记录的进一步更新。
<?php
If(isset($_POST['login'])){
$Pin=$_GET['pin'];
$ID =$_POST['ID'];
if($Pin!=''){
$update_count = mysql_query("SELECT * FROM Audit_Table_Update WHERE Field_name = 'Pin' and field_value='$pin');
if(!mysql_num_rows($update_count)){
$result = mysql_query("SELECT * FROM pin WHERE Pin = '$Pin'");
$test = mysql_fetch_array($result);
mysql_query("UPDATE pin SET appid ='$num' WHERE Pin= '$Pin'")
or die(mysql_error());
mysql_query("INSERT INTO AUDIT_TABLE_UPDATES (TABLE_NAME, FIELD_NAME, FIELD_VALUE,TIME_UPDATED) VALUES('Pin','appid',$num,systemtime)")
or die(mysql_error());
header("location:compet_applicant.php");
} // end if update count
}
}
?>
<?php
if (isset($_POST['login'])) {
$Pin = $_GET['pin'];
$ID = $_POST['ID'];
if ($Pin != '') {
$result = mysql_query("SELECT * FROM pin WHERE Pin = '$Pin'");
$test = array();
while ($row = mysql_fetch_array($result)) {
$test[] = array_map('utf8_encode', $row);
}
if ($test["number_update"] == 1) { //Checking already updated
//Notify user that they have already updated
} else {
mysql_query("UPDATE pin SET appid ='$num',number_update = 1 WHERE Pin= '$Pin'") or die(mysql_error());
}
header("location:compet_applicant.php");
}
}
?>
按照 Neo 先生的建议,在数据库表中再添加一个字段"number_update",并将您的代码替换为上面的代码。