How Can I Query for Unique Value and Update another Field in Same Table If return True mysql php

后端 未结 3 352
一个人的身影
一个人的身影 2021-01-29 10:46

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 retur

3条回答
  •  爱一瞬间的悲伤
    2021-01-29 11:10

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

提交回复
热议问题