Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:58:56+00:00 2026-06-18T03:58:56+00:00

Im trying to get a php form to either autopopulate a user ID field

  • 0

Im trying to get a php form to either autopopulate a user ID field from a cookie or if it is a new pc then give the user the option of ‘remember me’. when I manually add a cookie and then load the form page it populates the user box correctly, but I cant seem to set a cookie when it is posted from the form itself.

Code from the php form:

<form action="./post_cookies.php" method="post" id="HOME">
    <div id="nav">
        <ul>
            <li><i>Whats your username:</i></li>
           <li><i><input type="text" size="40" name="User_ID" 

           <?php
if (isset($_COOKIE["user"]))
  echo "value=\"" . $_COOKIE["user"] . "\"</i></li>";
else
  echo "placeholder=\"12345\"></i></li>";
?> 
            <li><i>Remember me: <INPUT TYPE="checkbox" NAME="remember" VALUE="1"> Yes</i></li>
        </ul>
    </div>

<div id="nav" style="text-align:center;">
        <ul>
            <li><i><button form="HOME" type=submit style="width:200px;height:40px">Submit</button></i></li>
        </form>
        </ul>
    </div>

</div>

this form posts to ‘post_cookies.php’ the code is:

   <?php
// creating a variable to store the timestamp in
$posttime = time();

// if the remember me checkbox returns a 1 then add the users, username as a cookie

if($_POST[remember]==1)
{   
    setcookie('user', $_POST[User_ID], $posttime + 3600);        // Sets the cookie 
}

// this is where the data base connection would go

header("Location: http://www.domain.com/index.php");
?>

The idea is that if the ‘remember me’ is checked then the post_cookies.php will set a cookie with the usersID.

I cant see where post_cookies.php is going wrong and not setting a cookie.
any assistance is greatly appreciated.

thanks!
Mathew

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:58:57+00:00Added an answer on June 18, 2026 at 3:58 am

    It should be:

    if ($_POST['remember'] == 1) {   
        setcookie('user', $_POST['User_ID'], $posttime + 3600);        // Sets the cookie 
    }
    

    The array key is in quotes. Try that

    Same with

    $_POST['User_ID']
    

    Also

    echo "value=\"" . $_COOKIE["user"] . "\"</i></li>";
    

    Is missing a closing > before the </i>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get my form to submit when a user either clicks
I am trying to submit a form with method GET and action index.php?id=3. The
Using php I am trying to get some data from a .csv file which
I am trying to get data back from a PHP file assigned with GET
I am trying to get a HTML/PHP form to submit properly. Some details: base
I'm trying to get information from a list(listDIV) to show up in my form
I'm trying to have an array display information inputted from a PHP-created HTML form.
I'm trying to insert the current date from a php form into a database.
I am trying to get php's namespace technique down but having some issues here:
I'm trying to get php to automatically pass the session ID via url, even

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.