Forum Moderators: coopster

Message Too Old, No Replies

php form using $ SESSION and unset. what is wrong?

         

Cheetahten

6:53 pm on Oct 11, 2007 (gmt 0)

10+ Year Member



Am not sure what I am doing wrong... THANK YOU message never shows up if UNSET AFTER

here is my code
--- TEST.PHP



<?php
session_start();
ob_start();
?>
<html>
<head>
<title>hello World!</title>
</head>

<body>

<?php
if ($_POST["submit"])
{
if (trim($_POST['name']) == "")
$formMsg = "Name is needed!";


if ($formMsg == "" ){
emailUser($name);
header("Location: test.php");
}
}

if ($_SESSION[sentOk]){
$formMsg = "Thank you for Submitting!";
unset($_SESSION[sentOk]);
}

print "
<form action='$PHP_SELF' method='post'>
<div>
$formMsg
</div>

<div>
<label for='name'>
Name:&nbsp;&nbsp;
</label>
<span>
<input type='text' name='name' id='name' maxlength='20' tabindex='1' />
</span>
</div>
<div>
<label>
&nbsp;&nbsp;
</label>
<input id='submit' name='submit' title='Submit' type='submit' value='Submit' tabindex='2'/>
</div>
</form>
";
?>
</body>
</html>

<?php
function emailUser($name){
//Hurray email was send oki-dokie...
$_SESSION[sentOk] = true;
return;
}
?>


[edited by: Cheetahten at 7:00 pm (utc) on Oct. 11, 2007]

eelixduppy

8:33 pm on Oct 11, 2007 (gmt 0)



Hello, and Welcome to WebmasterWorld!

I believe you aren't receiving the output because of your use of ob_start(). You either have to remove this, which it isn't really needed here, or you have to dump the contents of the buffer to the browser using ob_end_flush [us2.php.net].

If I were you, though, I would just remove it.

Cheetahten

9:03 pm on Oct 11, 2007 (gmt 0)

10+ Year Member



I SOLVED IT.. here it is incase someone else needed it

Simply call session_write_close(); before setting the redirect header.


session_write_close();
header("Location: test.php");

Thanks