It's an isset statement then inside it is an if-else statement. If I click the button add contract, it already goes to the addcontract-success.php even the fields are empty.
<?php
if(isset($_POST["btnAddContract"])){
if(empty($_POST["contract_number"])){
$contract_numberErr = "Contract Number is required!";
}else{
$contract_number = $_POST["contract_number"];
}
if(empty($_POST["contract_type"])){
$contract_typeErr = "Contract Type is required!";
}else{
$contract_type = $_POST["contract_type"];
}
if(empty($_POST["company_name"])){
$company_nameErr = "Company Name is required!";
}else{
$company_name = $_POST["company_name"];
}
if(empty($_POST["contact_number"])){
$contact_numberErr = "Contact Number is required!";
}else{
$contact_number = $_POST["contact_number"];
}
if(empty($_POST["booking_date"])){
$booking_dateErr = "Booking Date is required!";
}else{
$booking_date = $_POST["booking_date"];
}
if(empty($_POST["weight"])){
$weightErr = "Weight is required!";
}else{
$weight = $_POST["weight"];
}
if(empty($_POST["destination"])){
$destinationErr = "Destination is required!";
}else{
$destination = $_POST["destination"];
}
if(empty($_POST["price"])){
$priceErr = "Price is required!";
}else{
$price = $_POST["price"];
}
if(empty($_POST["goods"])){
$goodsErr = "Number of Goods is required!";
}else{
$goods = $_POST["goods"];
}
if(empty($_POST["transportation_mode"])){
$transportation_modeErr = "Transportation Mode is required!";
}else{
$transportation_mode = $_POST["transportation_mode"];
}
if(empty($_POST["departure_time"])){
$departure_timeErr = "Departure Time is required!";
}else{
$departure_time = $_POST["departure_time"];
}
if(empty($_POST["pickup_date"])){
$pickup_dateErr = "Pickup Date is required!";
}else{
$pickup_date = $_POST["pickup_date"];
}
if(empty($_POST["pickup_time"])){
$pickup_timeErr = "Pickup Time is required!";
}else{
$pickup_time = $_POST["pickup_time"];
}
if(empty($_POST["status"])){
$statusErr = "Status is required!";
}else{
$status = $_POST["status"];
}
mysqli_query($connections, "INSERT INTO tblcontract(contract_number, contract_type, company_name, contact_number, booking_date, weight, destination, price, goods, transportation_mode, departure_time, pickup_date, pickup_time, status)
VALUES('$contract_number', '$contract_type', '$company_name', '$contact_number', '$booking_date', '$weight', '$destination', '$price', '$goods', '$transportation_mode', '$departure_time', '$pickup_date', '$pickup_time', '$status')");
header("Location: addcontract-success.php");
}
?>
I think I'm missing something in the logic of my if-else statement.
Might me missing something here: header("Location: addcontract-success.php"); I'm thinking to have an else before mysqli_query but it still doesn't work.
Aucun commentaire:
Enregistrer un commentaire