如果返回 True mysql php,如何查询唯一值并更新同一表中的另一个字段 [英] How Can I Query for Unique Value and Update another Field in Same Table If return True mysql php

查看:32
本文介绍了如果返回 True mysql php,如何查询唯一值并更新同一表中的另一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 Pin 字段值与用户输入的 pin 相同,我想更新 mysql 表 pin.在这种情况下,我想在选择查询返回 true 后更新 pin 表中的 appid 字段.

I want to update mysql table pin if Pin field value is the same as the user input pin.In this case, I want to update appid field in the pin table once the the select query returns true.

<?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,请登录.如果是0,允许更新

I think you should add one more field like: number_update into your pin table first. Default value is 0 First 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());
}

这篇关于如果返回 True mysql php,如何查询唯一值并更新同一表中的另一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆