我想检查一个id是否在user表中注册,如果它在user表中注册,则输入MySQL,如果不是,则返回无效id。到目前为止,我已经做到了这一点,即在不进行任何检查的情况下进入。当in在tbl_user
中注册时,这是tbl_attendance
。我从一个叫阿杜伊诺的人那里拿到身份证。
<?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);
}
?>
发布于 2018-06-04 20:52:42
这段代码应该会做你所要求的事情。您应该考虑使用预准备语句(例如PDO),因为mysqli库已被弃用。
<?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);
?>
https://stackoverflow.com/questions/50678794
复制相似问题