0

i have a basic script where in i check if the content is inputted or not .
If the content is not present i redirect to the same page also echoing a statement that u have not entered any data , but the echo message is not being printed.

the below is redirect.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ?
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

<form action="redirect.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />


</form>
</body>
</html>

the below is redirect.php

<?php

if (trim ($_POST['yourname']) == "")
{
	echo " u have not entered any data ";
	header ("Location: redirect.html");
	exit;
}

echo $_POST['yourname'];

?>
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by rahul8590
0

its because of your header() redirection, before the echo can output your message the page has been redirected. you can try this

<?php

if (trim ($_POST['yourname']) == "")
{
	echo "<script>alert('u have not entered any data');
window.location='redirect.html'</script>";
	
}

echo $_POST['yourname'];

?>
0

well that certainly worked , kudos to you .
but isnt that javascript which u have incorporated ? i guess so
secondly i printed the echo statement first and then the header function , i dont get why should it directly jump to header func when a echo statement is encountered before

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.