paulmo Posted December 30, 2008 Share Posted December 30, 2008 how to recall name submitted in form for returning user? and possibly echo as well on same page in greeting? lots of code googling (pop up boxes, cgi page links), but no success yet with what would seem to be a basic procedure. thanks for direction— <form name="myform" action="process.php" method="POST"> <input type="hidden" name="check_submit" value="1"/> </p><p>First Name: <input type="text" name="name" class="buttonsb"/> Quote Link to comment Share on other sites More sharing options...
paulmo Posted December 30, 2008 Author Share Posted December 30, 2008 trying with jquery...is this getting closer? thanks <script type="text/javascript" src="jquery-1.2.6.min.js"></script> $.cookies.get('name', 'text'); $.cookies.set('name'); <form method="post" action="contact.php"> <input type="hidden" name="redirect" value="xxx.php" /></p><p> Name: <br/> <input name="name" type="text" size="20" class="buttonsb"></p> <p><input type="submit" name="submit" value="Send" class="buttons"/> </p> </form> Quote Link to comment Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 You would do something like this. if (isset($_COOKIE["user"])) { $user_name = $_COOKIE["user"]; } else { $user_name = "Guest"; } ?> </pre> <form name="myform" action="process.php" method="POST"> First Name: < You also have to set the cookie somewhere, (maybe after the user logs in), by doing: setcookie("user", "name_here", time()+3600); Try it and come back with specific questions. Quote Link to comment Share on other sites More sharing options...
paulmo Posted December 30, 2008 Author Share Posted December 30, 2008 thanks maq this is what i've got. not sure where to set cookie. there's no log in, only a form that gets processed by process.php. want to recall first name only so when user returns, name will be in form field (or use to create greeting). <?php if (isset($_COOKIE["user"])) { $user_name = $_COOKIE["user"]; } else { $user_name = "Guest"; } ?> <form name="myform" action="process.php" method="POST"> <input type="hidden" name="check_submit" value="1"/> </p><p>First Name: <?php echo $user_name; ?> <input type="text" name="name" class="buttonsb"/></p><p> <input type="submit" value="Process" class="buttons" onclick="return CapitalizeNames()"> </form> setcookie("user", "name_here", time()+3600); Quote Link to comment Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 there's no log in, only a form that gets processed by process.php. Then you should set it in process.php. It should look something like this: setcookie("user", $_POST['name'], time()+3600); So when you submit to process.php you get the text field for the name they typed in. Keep in mind time()+3600 is in seconds. So 3600 = 1 hour. You should modify if you want the cookie to last longer. Quote Link to comment Share on other sites More sharing options...
paulmo Posted December 30, 2008 Author Share Posted December 30, 2008 anywhere put setcookie on process.php page getting this: Warning: Cannot modify header information - headers already sent Quote Link to comment Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 Code? Quote Link to comment Share on other sites More sharing options...
paulmo Posted December 30, 2008 Author Share Posted December 30, 2008 this process.php processes the form and inserts values in database table. i've put the setcookie near the bottom. again, error message was appearing no matter setcookie location. thanks! <?php ini_set("display_errors", 1); error_reporting(E_ALL); mysql_connect("xxx", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); $name = mysql_real_escape_string($_POST['name']); $theme = mysql_real_escape_string($_POST['theme']); mysql_query("INSERT INTO xxx (name, theme, created) VALUES ('$name', '$theme', NOW()) ") or die(mysql_error()); $row_id = mysql_insert_id(); //Put it in a variable for later ?> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script type="text/javascript"> $(function(){ //This syntax will execute when the page is done loading $.post("geo.php", {geoip_city: geoip_city(), geoip_region_name: geoip_region_name(), row_id: '<?php echo $row_id; ?>' //Pass it with the JavaScript // },function(message){ alert(message); }); }); </script> <?php switch (intval(date('n'))) { case 1: case 2: case 3: #there's about 10 pages of code in here with $phrase variables that echo statements dependent on radio form field] } setcookie("user", $_POST['name'], time()+3600); ?> Quote Link to comment Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 Put it towards the top. I assume you're going to have some validation for user names. Right after you validate you should set the cookie. For now just put it here: ini_set("display_errors", 1); error_reporting(E_ALL); mysql_connect("xxx", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); $name = mysql_real_escape_string($_POST['name']); $theme = mysql_real_escape_string($_POST['theme']); mysql_query("INSERT INTO xxx (name, theme, created) VALUES ('$name', '$theme', NOW()) ") or die(mysql_error()); $row_id = mysql_insert_id(); //Put it in a variable for later setcookie("user", $_POST['name'], time()+3600); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.