Jump to content

text element cookie help


paulmo

Recommended Posts

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"/>

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.