不允许用户选择相同的日期。 PHP,MYSQLi

问题描述 投票:-1回答:1

我试图不允许用户在同一天下订单。我的SQL和PHP不会从此代码返回错误。但是,它不会返回任何内容,甚至不会下订单。

任何帮助将不胜感激

    //Check if the date has been taken
    $sql = "SELECT * FROM orders WHERE date='$date'";
    $result = mysqli_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);

    if ($resultCheck > 1) { 
        header("Location: ../placeorder.php?order=taken");
        exit();
    } else { 
        header("Location: ../placeorder.php");
        exit(); 
    }
}

//Insert orders into database
$sql = "INSERT INTO orders (user_id, price, time, date, type, square_ft, materials ) VALUES ('$userid','$price', '$time', '$date', '$type', '$square_ft','$materials' );";
mysqli_query($conn, $sql);
header("Location: ../placeorder.php?=order=success");
exit(); 
php sql mysqli
1个回答
0
投票

我所要做的就是在$ resultCheck之后删除else语句。加集($ resultCheck> 0)。

        //Check if the date has been taken
            $sql = "SELECT * FROM orders WHERE date='$date'";
            $result = mysqli_query($conn, $sql);
            $resultCheck = mysqli_num_rows($result);

                if ($resultCheck > 0) { 
                    header("Location: ../placeorder.php?order=taken");
                    exit();
                } 
    }

    //Insert orders into database
        $sql = "INSERT INTO orders (user_id, price, time, date, type, square_ft, materials ) VALUES ('$userid','$price', '$time', '$date', '$type', '$square_ft','$materials' );";
        mysqli_query($conn, $sql);
                header("Location: ../placeorder.php?=order=success");
                exit(); 

}

© www.soinside.com 2019 - 2024. All rights reserved.