I have some code that is entering values into a database. I have an IF statement at the start to check if the string $jobno
is empty and if it is, it redirects back to the form. But its not redirecting just runs the code successfully.
if ($jobno=='') {
header( 'Location: add_job.php?error=1');
}
What am I doing wrong?!
<?php
$status=$_POST["status"];
$jobno=$_POST["jobno"];
$number=$_POST["number"];
$street=$_POST["street"];
$suburb=$_POST["suburb"];
$city=$_POST["city"];
$first_name=$_POST["first_name"];
$first_name = ucfirst($first_name);
$last_name=$_POST["last_name"];
$last_name = ucfirst($last_name);
$landline=$_POST["landline"];
$mobile=$_POST["mobile"];
$fax=$_POST["fax"];
$email=$_POST["email"];
if ($jobno=='') {
header( 'Location: add_job.php?error=1');
}
$con=mysqli_connect("server","user","pass","database");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to database: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO jobs (status, jobno, number, street, suburb, city, first_name, last_name, landline, mobile, fax, email)
VALUES ('$status', '$jobno', '$number', '$street', '$suburb', '$city', '$first_name', '$last_name', '$landline', '$mobile', '$fax', '$email')");
mysqli_close($con);
header( 'Location: photo_upload.php?new_job_success=y&jobno=' . $jobno ) ;
?>