Jump to content

Help setting cookie from form


blesseld

Recommended Posts

I'm almost giving up...I have no idea what to ...here's where I got

 

before HTML

<?php

    $uname =  $_POST['uname'];
    $idnumber = $_POST['idnumber'];
    $self =  $_SERVER['PHP_SELF'];

    if( ( $uname != null ) and ( $idnumber != null ) )
        {
          setcookie( "username", $uname , time() + 86400 );        // 24 hours
          setcookie( "identnumber", $idnumber, time() + 86400 );
        }
elseif (isset($_COOKIE['username']))
        {
        $user = $_COOKIE['username'];
        $color= $_COOKIE['identnumber'];
        }
    else
        {
        $user =  $_POST['uname'];
        $color = $_POST['idnumber'];
        }
?>

 

form

 

<form method="post" action="freeform_a.php">
  Your Name: <input name="uname" type="text" size="20" maxlength="20" value="<?php echo( $uname ); ?>" /><br />
  Your ID: <input name="idnumber" type="text" size="20" maxlength="6" value="<?php echo( $idnumber ); ?>" /><br />
  <input type="submit" value="Add Me!"/>
</form>

 

Action page

 

<?php
$con = mysql_connect("localhost","justadz_form","form1");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("justadz_testmail", $con);

$sql="INSERT INTO freeFormTable (ID, uname, idnumber)
VALUES
('NULL','$_POST[uname]','$_POST[idnumber]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
else header( "Location: http://freeaisle.com/?page_id=6" );
//Location is my thankyou page
mysql_close($con)
?>

 

I just want to get the cookie to save and then fill in the form for me...just to get something to work..but what i ultimatly need is if the user has already submitted, and a cookie has been created , I don't want them to see the form..somthing with includes maybe...

But for now I just want to see the cookies workign...please help

Link to comment
https://forums.phpfreaks.com/topic/142738-help-setting-cookie-from-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.