So if the Material number doesn't match the Input with the data stored in database it should redirect to requestfailure.php page and it doesn't store it in database. If it exists it should redirect to requestsuccess.php and store the value in database.
The problem here is, It works fine but the redirection is not working as im always getting redirected to requestsuccess.php no matter it gets stored or not.
<?php
if(isset($_POST['submit'])) {
include_once 'dbh.inc.php';
$mnum = mysqli_real_escape_string($conn, $_POST['mnum']);
$mcat = mysqli_real_escape_string($conn, $_POST['mcat']);
$mmess = mysqli_real_escape_string($conn, $_POST['mmess']);
$mcode = mysqli_real_escape_string($conn, $_POST['mcode']);
$mdev = mysqli_real_escape_string($conn, $_POST['mdev']);
//error handlers
//check for empty fields
if(empty($mnum) || empty($mcat)){
header("Location: ../index.php?index=empty");
exit();
} else {
//check if the request already exists
$sql = "SELECT * FROM pending WHERE Material = '$mnum'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0) {
header("Location: ../index.php?index=requestalreadyexists");
exit();
} else {
$sql = "INSERT INTO pending (Material, ShopFloor, Message, Code, Device, Description, Location) SELECT '$mnum','$mcat','$mmess','$mcode','$mdev', Description, Location FROM list WHERE Material = '$mnum';";
mysqli_query($conn, $sql);
header("Location: ../requestsuccess.php");
}
}
} else {
header("Location: ../requestfailure.php");
exit();
}
Also if anyone can tell me how to debug this and where my if / else is going wrong.