Results 1 to 6 of 6

Thread: Parse Error

  1. #1

    Thread Starter
    Junior Member Neden's Avatar
    Join Date
    May 2004
    Location
    Canada
    Posts
    22

    Angry Parse Error

    PHP Code:
    <?

    <form method='post'>

    Username
    <input type='text' name='alias' value='' size='30' maxlength='25'>

    <input type='password' name='pass' value='' size='30' maxlength='10'>

    IP
    <input type='hidden' name='myip' value='' size='30' maxlength='10'>

    <input type='hidden' name='action' value='join'>
    <input type='submit' name='' value='Submit!'>

    mysql_query("INSERT INTO `users` VALUES (
    '$alias',
    '$pass',
    '$myip');");

    }

    ?>
    Parse error on line 3

    I don't see any problems

    Its Neden

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Parse Error

    Originally posted by Neden
    PHP Code:
    <?

    <form method='post'>

    Username
    <input type='text' name='alias' value='' size='30' maxlength='25'>

    <input type='password' name='pass' value='' size='30' maxlength='10'>

    IP
    <input type='hidden' name='myip' value='' size='30' maxlength='10'>

    <input type='hidden' name='action' value='join'>
    <input type='submit' name='' value='Submit!'>

    mysql_query("INSERT INTO `users` VALUES (
    '$alias',
    '$pass',
    '$myip');");

    }

    ?>
    Parse error on line 3

    I don't see any problems

    <form method='post'> is not PHP.

    Whatever is not PHP, put outside the <? ?> tags.

  3. #3
    Junior Member
    Join Date
    Apr 2004
    Location
    Stockholm, Sweden
    Posts
    29
    Alternatively you could echo it inside the PHP-code.

    PHP Code:
    <?php
    echo "<form method=\"post\">";
    // Rinse-repeat for the rest of the HTML-tags and text
    ?>
    Note that you should use double quotes for HTML-attributes, and that you need to escape these (with the backslash \ character) so PHP will print these out.
    If there is a way to solve your problems, there is no need to worry; if there is no way to solve your problems, there is no point to worry.

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by KTottE
    Alternatively you could echo it inside the PHP-code.

    PHP Code:
    <?php
    echo "<form method=\"post\">";
    // Rinse-repeat for the rest of the HTML-tags and text
    ?>
    Note that you should use double quotes for HTML-attributes, and that you need to escape these (with the backslash \ character) so PHP will print these out.
    Or do:

    PHP Code:
    <?php
    echo '<form method="post">';
    // Rinse-repeat for the rest of the HTML-tags and text
    ?>
    So that no escaping is required.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Junior Member
    Join Date
    Apr 2004
    Location
    Stockholm, Sweden
    Posts
    29
    That's true, but then it should be noted that single quotes is only to be used when no evaluation is required, that is, only use them for printing out plain strings.
    If you need echo to evaluate something, you need to use double quotes.

    PHP Code:
    // Yes:
    echo 'Hello World!';

    // Yes:
    $string "Hello World";
    echo 
    "This is my string:\n $string";

    // No:
    $string "Hello World";
    echo 
    'This is my string:\n $string'
    I'm sure you probably know this already, The Hobo, but it's worth noting for Neden, so he doesn't use single/double quotes wrong
    If there is a way to solve your problems, there is no need to worry; if there is no way to solve your problems, there is no point to worry.

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Parse Error

    Originally posted by Neden
    PHP Code:
    <?

    <form method='post'>

    Username
    <input type='text' name='alias' value='' size='30' maxlength='25'>

    <input type='password' name='pass' value='' size='30' maxlength='10'>

    IP
    <input type='hidden' name='myip' value='' size='30' maxlength='10'>

    <input type='hidden' name='action' value='join'>
    <input type='submit' name='' value='Submit!'>

    mysql_query("INSERT INTO `users` VALUES (
    '$alias',
    '$pass',
    '$myip');");

    }

    ?>
    Parse error on line 3

    I don't see any problems

    A few more things to note:

    1. You have no closing form tag.
    2. You have no name for your submit button.
    3. You're using native globals. Use superglobals (see topmost thread in this forum).
    4. Your code is written badly. You need to create some kind of conditional:

    PHP Code:
    if (isset($_POST['submit'])) {
        
    // call your query here
    } else {
        
    // output your form here

    Or if you want the form to reappear when you're done, do this:

    PHP Code:
    if (isset($_POST['submit'])) {
        
    // call your query here
    }

    // output your form here 
    If you leave it your way, you're going to get a lot of blank records.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width