Jump to content

AnimaStone

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Posts posted by AnimaStone

  1. I have an exercise for school that I have to work out. My teacher is letting us figure it out ourselves, but I've ran into some troubles:

     

    - We have to make 2 files: sescook1.php and sescook2.php.

    - We have to make a form for the user to fill out their name and favorite color (in sescook1.php).

    - We have to check the input (whether there is input or no). If there's isn't any input, we have to echo 'Please fill out __' (in sescook1.php)

    - We have to store the name in a session variable and the color in a cookievariable (in sescook1.php)

    - If both fields are filled in, we ave to show a link 'go to the next page' (where 'next page' is an URL to sescook2.php).

    - All info has to be shown in sescook2.php (Entered name: __, Entered color: ___)

    - You have a link 'Go back to previous page' (where 'previous page' is an URL to sescook1.php)

     

    My code:

    <?php

    session_start();

    function checkContent() {

    if($_POST["name"] == "")

    echo "Please enter your name";

    elseif($_POST["favcolor"])

    echo "Please enter your favorite color";

    else

    echo "Go to <a href='http://localhost/webadv1011/PHPCookiesSessies/sescook2.php'>next page";

    }

    ?>

     

    <form name="color" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="<?php checkContent(); ?>">

    <p>Name: <input type="text" name="naam" /></p>

    <p>Favourite color: <input type="text" name="favcolor" /></p>

    <p><input type="submit" name="submit" value="send" /></p>

    </form>

     

    This is the code I got so far. My problem is that the page refreshes itself after it does the checkContent function. I'm also not sure how I save my name in a session variable and the color in a cookie variable (and pass them to the next page as well!).

     

    We haven't learned anything on cookies and sessions except our own trial and error and things I found on the internet. Unfortunately, I can't really find lots of useful info (most people refer to Ajax, but we can only use php), or I'm looking in the wrong place.

     

    Thanks for your help in advance! :)

     

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