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'];

?>

Recommended Answers

All 2 Replies

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'];

?>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.