首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何检查一条记录是否已注册

如何检查一条记录是否已注册
EN

Stack Overflow用户
提问于 2018-06-04 18:45:20
回答 1查看 81关注 0票数 -1

我想检查一个id是否在user表中注册,如果它在user表中注册,则输入MySQL,如果不是,则返回无效id。到目前为止,我已经做到了这一点,即在不进行任何检查的情况下进入。当in在tbl_user中注册时,这是tbl_attendance。我从一个叫阿杜伊诺的人那里拿到身份证。

代码语言:javascript
复制
<?php
include ('connection.php');
$sql_insert = "INSERT INTO tbl_attendance (rfid_uid) VALUES ('".$_GET["rfid_uid"]."')";
if(mysqli_query($con,$sql_insert))
{
mysqli_close($con);
}

?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 20:52:42

这段代码应该会做你所要求的事情。您应该考虑使用预准备语句(例如PDO),因为mysqli库已被弃用。

代码语言:javascript
复制
<?php

    //Include the mysql connection to the database
    include ('connection.php');

    //Find the existing RFID rows
    $result = mysqli_query($con, "SELECT id FROM tbl_user WHERE rfid_uid = '". $_GET["rfid_uid"] ."'");

    //Count the number of rows
    $count = mysqli_num_rows($result);

    if( $count == 1 ){ //If the user exists in the tbl_usr
        //Build the table insert query
        $sql_insert = "INSERT INTO tbl_attendance (rfid_uid) VALUES ('".$_GET["rfid_uid"]."')";

        //Execute that query
        if( mysqli_query($con, $sql_insert) ){
            echo "Attendance registered successfully!";    //Success message
        } else {
            echo "Attendance failed to register!";         //Failure message
        }
    } else {
        //Display the "Invalid ID Message"
        echo "Invalid id";
    }

    //Close the mysql connection object
    mysqli_close($con);

?>
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50678794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档