本文介绍了我如何检查mysql表的唯一值,并使用php将其更新一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想更新mysql表一次.如果要再次更新,则应显示消息"ID已在使用中,请登录"

I want to update mysql table but only once. If you want to update it again it should give message "ID Already in Use, Pls login"

<?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,请允许更新

I think you should add one more field like: number_update into your pin table first. Default value is 0First time update, it will have value is 1 and you could check that value,if it is 1, will alert ID Already in Use, Pls login. If it is 0, allow to update

$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());
}

这篇关于我如何检查mysql表的唯一值,并使用php将其更新一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:55