Reputation: 67
Can someone assist me with figuring out why my form isn't doing anything/not functioning. I am very new to programming so bear with me if you can. When the submit button is pressed nothing at happens. I want it to recall something based off of what is entered in the text field. (nothing in particular, just trying to experiement/learn.)
This is in my html file:
<form action="process.php" method="post">
<input type="text" name="fname" valude="pdate"/>
this is in my process.php file:
$fdate = $_POST['fname'];
setcookie ("user", $fdate, time() +60*60*24*365);
if (isset($_COOKIE['user'])){
var_dump ($_COOKIE);
}
else{
header('fname:index.html');
}
Thanks
Upvotes: 0
Views: 118
Reputation: 360592
The PHP superglobals (_COOKIE, _FILES, _POST, _GET, _REQUEST) are set when the script is first started up, and then PHP never touches them again.
When you do your set cookie, that cookie will NOT magically appear in the $_COOKIE superglobal until the NEXT page request. It has to be round-tripped to the client first.
Upvotes: 2
Reputation: 13535
This code Worked For Me :
Test.php
< ?php
if( isset( $_POST['fname'] ) )
{
setcookie ("user", $_POST['fname'], time() +60*60*24*365);
}
if( isset( $_COOKIE['user'] ) )
{
echo 'COOKIE IS SET';
} else
{
echo 'COOKIE NOT SET';
}
?>
<form action="" method="post">
<input type="text" name="fname" value="pdate" />
<button type="submit">Go</button>
</form>
Upvotes: 0