rocky48 Posted May 30, 2014 Share Posted May 30, 2014 I am trying to find a way to check if a user has already entered their email address in my MySQL database. If they have an entry then it jumps to another script that avoids the questionnaire, but if they have no entry, then they do the questionnaire. I have tried using header('Location: /questionnaire.html'); but I get this error warning: Warning: Cannot modify header information - headers already sent by (output started at /homepages/43/d344817611/htdocs/Test/questionnaire_connect.php:14) in /homepages/43/d344817611/htdocs/Test/eCheck.php on line 16 The script I am using: <?php include('questionnaire_connect.php'); doDB12(); if ($_POST["email"] == "") { header("Location: emailChecker.html"); exit; } else { //check that email is in list emailChecker($_POST["email"]); //get number of results and do action if (mysqli_num_rows($check_res) < 1) { //free result mysqli_free_result($check_res); header('Location: /questionnaire.html'); }else { header('Location: /Alt_inputform.html'); } } //close connection to MySQL mysqli_close($mysqli); ?> The emailChecker is a function in the DB connect script: function emailChecker($email) { global $mysqli, $check_res; //check that email is not already in list $check_sql = "SELECT id FROM questionnaire WHERE email = '".$email."'"; $check_res = mysqli_query($mysqli, $check_sql) or die(mysqli_error($mysqli)); } Is there another way I can redirect the program flow other than using Header? Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted May 30, 2014 Share Posted May 30, 2014 Should write the script that can use header before any output. But can use meta refresh <META http-equiv="refresh" content="0;URL=emailChecker.html"> Quote Link to comment Share on other sites More sharing options...
FraanXT Posted May 30, 2014 Share Posted May 30, 2014 You can use that too: die("<script>location.href = 'path_that_you_want.file_extension'</script>"); Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 30, 2014 Share Posted May 30, 2014 your goal would be to find and fix what is causing the error. based on where the output is being reported at, line 14 of questionnaire_connect.php, you likely have some white-space after the closing ?> tag in that file or something in questionnaire_connect.php is producing unexpected output. what is on line 14 questionnaire_connect.php? Quote Link to comment Share on other sites More sharing options...
Solution rocky48 Posted June 1, 2014 Author Solution Share Posted June 1, 2014 Opps! Left an echo on line 14. Now works fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.