gpt4 book ai didi

php - 关于php和mysql

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

我需要一个关于如何解决我的问题的简单建议。

这是我的函数 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/

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