Jump to content

Is there an alternative to Header to redirect to another script


rocky48
Go to solution Solved by rocky48,

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.