我需要一个关于如何解决我的问题的简单建议。
这是我的函数 php:
$userID = $_GET['user'];
$code = $_GET['code'];
if (empty($code) || empty($userID)){
die(error('Fill in all fields'));
}
我需要正确的代码来放置 $code,如果它不正确/不正确,我想要错误:代码不存在
(抱歉我的英语不好,但这不是我的自然语言)
我也已经尝试过这种方式:
if (!my_function()) {
// function returned a false value
}
但这并没有解决我的问题,因为当我将我生成的“giftcode”($code)放入输入框中时,它显示错误:!my_function
所以它不是,解决我的问题。
最佳答案
您的问题不清楚。请提供更多详细信息和错误消息
I need the right code to put $code if it isnt right/true, i want the error: Code does not exist
要避免此错误,您可以使用 isset 函数。 PHP isset() 函数检查变量是否可用... 您可以简单地尝试
if(isset($_GET['code']) && isset($_GET['user']) ){
if (empty($_GET['code']) || empty($$_GET['user'])){
die(error('Fill in all fields'));
}
更新:
I need to check if a value exists in a MySQL database table, please help me if you can, i need a simple code to prevent someone trying to redeem fake giftcodes in my site thats why i want a code to check if a value exists in mysql db table
if(isset($_GET['code'])){
$code = $_GET['code'];
$sql = "SELECT * FROM giftTable WHERE code = $code;
$result = mysqli_query($db,$sql);
if(mysqli_num_rows($result) == 1){
//do action
} else{
// else action
}
}
关于php - 关于php和mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55738503/