SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why won't this script work??

    Here it is, very simple:

    PHP Code:
    <?

    // if $name doesn't exist, display the first page

    if (!$name)

    {

    ?>

    <html>
    <form method="POST" action="login.php">
    So what's your name?
    <input type="text" name="name" size="10">
    <input type="submit" name="submit">
    </form>
    </html>

    <?

    }
    else
    {

    // if $name does exist, the form has been submitted

    switch ($name) {

    case 
    1"Luke"
    echo("<center><b>Welcome Luke!</center></b>");
    break;

    case 
    2"Neo":
    echo(
    "<center><b>Welcome to the Matrix!</center></b>");
    break;

    default:
    echo(
    "$name - Who are you?"); } }

    ?>
    When I run it I get this error:

    Parse error: parse error in /home/luchazard/www/login.php on line 30

    Thanks in advance!

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your switch statement was wrong:

    PHP Code:
    <?

    // if $name doesn't exist, display the first page

    if (!$name)

    {

    ?>

    <html>
    <form method="POST" action="login.php">
    So what's your name?
    <input type="text" name="name" size="10">
    <input type="submit" name="submit">
    </form>
    </html>

    <?

    }
    else
    {

    // if $name does exist, the form has been submitted

    switch ($name) {

    case 
    "Luke":
    echo(
    "<center><b>Welcome Luke!</center></b>");
    break;

    case 
    "Neo":
    echo(
    "<center><b>Welcome to the Matrix!</center></b>");
    break;

    default:
    echo(
    "$name - Who are you?"); } }

    ?>
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Sean! It works but I want to know what you changed (what did I have wrong)??

    Thanks!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How exactly did you get that form element in the title of the post?
    Last edited by therunes; Sep 6, 2001 at 23:41.

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in your cases, you don't put numbers.
    just
    PHP Code:
    case "whatever":
    //not
    case 1"whatever" 
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •