如果(!空($ COUPON_CODE)){
if(isset($coupon_code)){
$coupon = trim($coupon_code);
$checkcoupon = "SELECT couponCode FROM cc WHERE couponCode='".$coupon."'";
$results_coupon = mysqli_query($dbc,$checkcoupon);
if(mysqli_num_rows($results_coupon) == 1) {
echo true;
}
else {
echo false;
}
}
当我传递输入时,它需要检查数据库中的输入字符串,然后验证它是正确还是错误。但它没有用。为了调试我使用$ _GET ['coupon'],但它仍然出现在地址栏上。
<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>" >
<div class="form-group">
<label class="control-label"></label>
<div class="form-group">
<div class="input-group mb-3"> <input id="coupon" class="form-control" name="coupon" type="text" size="50" maxlength="13" /> </div>
</div>
</div>
<button type="submit" id="btn_submit" class="btn btn-primary">Submit</button>
</form>
对于我正在使用此代码的数据库。
$db_hostname = 'localhost';
$db_username = 'root';
$db_password = '';
$db_name = 'test';
$dbc = mysqli_connect ($db_hostname,$db_username, $db_password,$db_name);
if (mysqli_connect_errno()) {
echo "Could not establish database connection!";
exit();
}
答案 0 :(得分:0)
因为您尚未发布完整代码,请使用此代码并告诉我它是否有效
if(isset($_GET['coupon'])){
$coupon = trim($_GET['coupon']);
$checkcoupon = "SELECT couponCode FROM cc WHERE couponCode='".$coupon."'";
$results_coupon = mysqli_query($dbc,$checkcoupon);
if(mysqli_num_rows($results_coupon) == 1) {
return true;
}else{
return false;
}
}