gpt4 book ai didi

php - Mysql 检查 mysql 数据库中的值失败?

转载 作者:行者123 更新时间:2023-11-29 06:10:11 24 4
gpt4 key购买 nike

我有一个非常简单的用例,我正在检查表中是否存在某个值,但它似乎总是失败。这是我的 php 代码。

<?php

include "config.php";

$con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$dbname);

if(!$con)
{
echo "Connection Error".mysqli_connect_error();
}
else{
//echo "";
}
$device_id = $_POST["device_id"];
$check = "SELECT magazine_id FROM registered_buyers WHERE device_id = $device_id";
$rs = mysqli_query($con,$check);
if(mysqli_num_rows($con,$rs) == 0)
{
$jsonarray = $_POST["jsonarray"];
echo "This will be inserted".$jsonarray;

}else
{
echo "User already registered";
}

?>

谁能指出我的错误。欢迎任何帮助或建议。谢谢。

最佳答案

您可以尝试遵循此代码。

<?php
include "config.php";
$con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$dbname);
if(!$con){
echo "Connection Error".mysqli_connect_error();
}
$device_id = $_POST["device_id"];
$check = "SELECT magazine_id FROM registered_buyers WHERE device_id = ".$device_id;
$rs = mysqli_query($con, $check);
if(mysqli_num_rows($rs) == 0){
$jsonarray = $_POST["jsonarray"];
echo "This will be inserted".$jsonarray;
}else{
echo "User already registered";
}
?>

关于php - Mysql 检查 mysql 数据库中的值失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38760412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com