0

Here's my code:

<?php
include("conf.php"); 
if(isset($_POST['firstName']) && !empty($_POST['firstName'])) {
    $addQuery = "INSERT INTO members VALUES ('','".$_POST['firstName']."','".$_POST['lastName']."','".$_POST['loyalty']."','".$_POST['citizenType']."','".$_POST['grade']."','".$_POST['status']."')";
    mysqli_query($conn,$addQuery);
    header("Location: index.php"); 
    exit();
} else {
?>

<div class="container">
.
.
.
<?php } ?>

I cannot figure out why it doesn't redirect...

4
  • Doest it gives any errors? Is the location correct? Are the post variables set ? Commented Apr 14, 2017 at 23:15
  • No errors, just a blank screen. The redirection seems to be correct, I use it on another page... The $_POST are variable, yes Commented Apr 14, 2017 at 23:16
  • Your code is vulnerable to SQL injection attacks. You should use mysqli or PDO prepared statements with bound parameters as described in this post. Commented Apr 14, 2017 at 23:25
  • When you ask a question about an error, ALWAYS post the error log. To enable error reporting to your php code, append error_reporting(E_ALL); ini_set('display_errors', '1'); at the top of your script, what does it return ? Commented Apr 15, 2017 at 1:20

1 Answer 1

1

Based only on the code in your question, there's something wrong in the conf.php include file. It probably has a carriage return or other output that is preventing the header from operating since there is already output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.