I have a contact information form where users come and fill their info. There are different fields on form like name, email, phone no. ect. i don't want to let user to enter that detail again and again. i want to set cookies so when he/she will open that form user's last entered info should be in front of him. please help ASAP.

I have a contact information form where users come and fill their info. There are different fields on form like name, email, phone no. ect. i don't want to let user to enter that detail again and again. i want to set cookies so when he/she will open that form user's last entered info should be in front of him. please help ASAP.

Why dont u save the details in database and fetch them when required according to the user currently logged in...

thank you so much for your advice but its client's requirement to set cookies, no fetch from database. please help me..... :(

thank you so much for your advice but its client's requirement to set cookies, no fetch from database. please help me..... :(

Its a simple task to do...
when the user submits the form for first time, simply set the values in cookie..

setcookie("name", $name);
setcookie("email",$email);

and so on..
when u need to retrieve the values in cookie just do..

$name = $_COOKIE['name'];

and feed this value to ur form so user dont need to enter it repeatedly...
note: Using cookies for critical issues can be risky as user can have cookies disabled in browser but as for ur requirement it should do just fine..
Cheers!!

i have done the same job. see my code

<?php

$expire=time()+60*60*24*30;
$name=$_REQUEST['name'];
setcookie("username",$name, $expire);


?>

<html>

<?php

echo "cookie value".$_COOKIE["username"];

print_r($_COOKIE);
?>


<input name="name" value="<?=$_COOKIE["username"]?>" />

</body>
</html>

but issue is i am storing the value entered in name field as a cookie. but every time when i came and load form its blank as the $_REQUEST is blank. how can i tell to cookie, keep storing the last entered value of name field

i have done the same job. see my code

<?php

$expire=time()+60*60*24*30;
$name=$_REQUEST['name'];
setcookie("username",$name, $expire);


?>

<html>

<?php

echo "cookie value".$_COOKIE["username"];

print_r($_COOKIE);
?>


<input name="name" value="<?=$_COOKIE["username"]?>" />

</body>
</html>

but issue is i am storing the value entered in name field as a cookie. but every time when i came and load form its blank as the $_REQUEST is blank. how can i tell to cookie, keep storing the last entered value of name field

Just do a check if the $_REQUEST is empty, dont set the value in cookie.. this way only the first time cookie will be blank and as soon as the user enters a value for the first time, it will get stored in the cookie...

if(!(empty($_REQUEST['username']))){
$name=$_REQUEST['name'];
setcookie("username",$name, $expire);
}

Cheers!!