Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 30

Thread: unexpected ]

  1. #1
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts

    unexpected ]

    whats wrong with this

    PHP Code:

    <?php
    $submit 
    $_GET['submit'];
    $name $_POST['name'];
    $sname $_POST['sname'];
    $email $_POST['email'];
    $username $_POST['username'];
    $password $_POST['password'];
    $errormsg = array("No username Entered""No password entered or password too short""No email address entered or incorrect email address""You did'nt fill in your first/surname");
    $error '';
    $count "count($password)";
    if (isset(
    $submit){
    if (empty(
    $username))
    {
    $error .= $errormsg[0];
    }
    if (empty(
    $password) || $count )
    {
    $error .= $errormsg[1];
    }
    if (empty(
    $email) || !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email))
    {
    $error =. $errormsg[2];
    }

    if (empty(
    $name) || empty($sname))
    {
    $error .= $errormsg[3];
    }

    if (
    $error == '')
    {
    include 
    'sqlprotect.php';
    $datahost localhost;
    $dataname databasename;
    $datapase databasepass;
    $datauser databaseuser;

    mysql_connect($datahost$datauser$datapass) or die(mysql_error());
    mysql_select_db($dataname) or die(mysql_error());

    $check mysql_query("SELECT username FROM users WHERE username='$username'");  

    $user_exist mysql_num_rows($check); 

    if(
    $user_exist 0){ 
        echo 
    "I'm sorry but the username you specified has already been taken.  Please pick another one."
        unset(
    $username);   
        exit;   
    }
    $query "INSERT INTO users (name, sname, email, username, password, ) 
    VALUES('$name', '$sname', '$email', '$username', '$password')"

    mysql_query($query) or die(mysql_error()); 
    mysql_close();

    echo 
    "You have successfully registered please click <a href =\"/login.php\" >here</a> to log in";
    }else{
    echo 
    "$error";
    }
    }else{
    include 
    'prereg.php';
    }
    ?>
    error is Parse error: parse error, unexpected '[' in line 20
    Last edited by rafiki; 03-06-2007 at 06:41 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    The quotation mark:
    PHP Code:
    $count "count($password); 

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    omg shoulda spotted that, thanks, is that the only thing you can see wrong?

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by rafiki View Post
    omg shoulda spotted that, thanks, is that the only thing you can see wrong?
    • You don't need quotes around count() at all.
    • Just for simplicity you should have the errors in the places where they are going to be used. ie. $error .= 'Error message';
    • All of your $data* database info should be in quotes ie. $datahost = 'localhost';
    • While it is essentially the same result, you should use mysql_result() and SELECT COUNT(*) instead of selecting the field since you don't need the username text from the database, only to see if it exists.

    With your error text you should probably add linebreaks after each error, so if there is more than one each will be on a separate line.

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Inigoesdr View Post
    • You don't need quotes around count() at all.
    • Just for simplicity you should have the errors in the places where they are going to be used. ie. $error .= 'Error message';
    • All of your $data* database info should be in quotes ie. $datahost = 'localhost';
    • While it is essentially the same result, you should use mysql_result() and SELECT COUNT(*) instead of selecting the field since you don't need the username text from the database, only to see if it exists.
    With your error text you should probably add linebreaks after each error, so if there is more than one each will be on a separate line.
    first im going to get it working then worry about formatting
    making it look pretty is the least of my worrys


    PHP Code:
    <?php
    $submit 
    $_POST['submit'];
    $name $_POST['name'];
    $sname $_POST['sname'];
    $email $_POST['email'];
    $username $_POST['username'];
    $password $_POST['password'];
    $errormsg = array("No username Entered""No password entered or password too short""No email address entered or incorrect email address""You did'nt fill in your first/surname");
    $error '';
    $count "count($password)";
    if (isset(
    $submit)
    //line 12 <<-----
    if (empty($username))
    {
    $error .= $errormsg[0];
    }
    if (empty(
    $password) || $count )
    {
    $error .= $errormsg[1];
    }
    if (empty(
    $email) || !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email))
    {
    $error =. $errormsg[2];
    }

    if (empty(
    $name) || empty($sname))
    {
    $error .= $errormsg[3];
    }

    if (
    $error == '')
    {
    include 
    'sqlprotect.php';
    $datahost = ******;
    $dataname = ******;
    $datapase = *****;
    $datauser = *******;

    mysql_connect($datahost$datauser$datapass) or die(mysql_error());
    mysql_select_db($dataname) or die(mysql_error());

    $check mysql_query("SELECT COUNT(*) username FROM users WHERE username='$username'");  
    //updated that line ^^^^^^ this correct?
    $user_exist mysql_num_rows($check); 

    if(
    $user_exist 0){ 
        echo 
    "I'm sorry but the username you specified has already been taken.  Please pick another one."
        unset(
    $username);   
        exit;   
    }
    $query "INSERT INTO users (name, sname, email, username, password, ) 
    VALUES('$name', '$sname', '$email', '$username', '$password')"

    mysql_query($query) or die(mysql_error()); 
    mysql_close();

    echo 
    "You have successfully registered please click <a href =\"/login.php\" >here</a> to log in";
    }else{
    echo 
    "$error";
    }
    }else{
    include 
    'prereg.php';
    }
    ?>
    Parse error: parse error, unexpected '{' in rafiki.freehostia.com/register.php on line 12
    Last edited by rafiki; 03-06-2007 at 07:23 PM.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Put a parenthesis after the previous line to close the if():
    PHP Code:
    if (isset($submit))
    //line 12 <<----- 

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    first im going to get it working then worry about formatting
    making it look pretty is the least of my worrys
    Formatting it properly to begin with would help you prevent silly syntax mistakes in the first place. It's like saying you've got to get the house built first, then worry about where you put the door.

  • #8
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    While it is essentially the same result, you should use mysql_result() and SELECT COUNT(*) instead of selecting the field since you don't need the username text from the database, only to see if it exists.
    Although it's not really that much of an issue, I'd suggest to SELECT 1 FROM users WHERE etc., and then use mysql_num_rows().

    And Fumigator is correct. When you start with clean code, you won't have to redo everything. And it's not really about making it look pretty, it's about making it readable and easier to spot errors.

    Indentation is one of the biggest things that improves readability. And being consistent with that indentation.

  • #9
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    <?php
    $submit 
    $_POST['submit'];
    $name $_POST['name'];
    $sname $_POST['sname'];
    $email $_POST['email'];
    $username $_POST['username'];
    $password $_POST['password'];
    $errormsg = array("No username Entered""No password entered or password too short""No email address entered or incorrect email address""You did'nt fill in your first/surname");
    $error '';
    $count count($password);
    if (isset(
    $submit))
    {
    if (empty(
    $username))
    {
    $error .= $errormsg[0];
    }
    if (empty(
    $password) || $count )
    {
    $error .= $errormsg[1];
    }
    if (empty(
    $email))
    {
    $error =. $errormsg[2];
    }
    if (empty(
    $name) || empty($sname))
    {
    $error .= $errormsg[3];
    }

    if (
    $error == '')
    {
    include 
    'sqlprotect.php';
    $datahost = *********;
    $dataname = *******;
    $datapase = ******;
    $datauser = *******;

    mysql_connect($datahost$datauser$datapass) or die(mysql_error());
    mysql_select_db($dataname) or die(mysql_error());

    $check mysql_query("SELECT COUNT(*) username FROM users WHERE username='$username'");  

    $user_exist mysql_num_rows($check); 

    if(
    $user_exist 0){ 
        echo 
    "I'm sorry but the username you specified has already been taken.  Please pick another one."
        unset(
    $username);   
        exit;   
    }
    $query "INSERT INTO users (name, sname, email, username, password, ) 
    VALUES('$name', '$sname', '$email', '$username', '$password')"

    mysql_query($query) or die(mysql_error()); 
    mysql_close();

    echo 
    "You have successfully registered please click <a href =\"/login.php\" >here</a> to log in";
    }else{
    echo 
    "$error";
    }
    }else{
    include 
    'prereg.php';
    }
    ?>
    this is upto date code
    error is unexpected '.' on line 23
    but i dont see a . on line 23 :s
    Last edited by rafiki; 03-06-2007 at 07:49 PM.

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    $user_exist mysql_result(mysql_query("SELECT COUNT(*) username FROM users WHERE username='$username'"), 0); 
    Last edited by Inigoesdr; 03-06-2007 at 11:33 PM.

  • #11
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You have
    PHP Code:
    $error =. $errormsg[2]; 
    Instead of
    PHP Code:
    $error .= $errormsg[2]; 
    Be careful of what you're typing

  • #12
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Quote Originally Posted by Inigoesdr View Post
    PHP Code:
    $user_exist 0;
    $user_exist mysql_result(mysql_query("SELECT COUNT(*) username FROM users WHERE username='$username'"), 0); 
    Why the first line?

  • #13
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by aedrin View Post
    Why the first line?
    Fixed.

  • #14
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Fumigator View Post
    Formatting it properly to begin with would help you prevent silly syntax mistakes in the first place. It's like saying you've got to get the house built first, then worry about where you put the door.
    how do you suggest i format the code whilst doing it? is there like a "Standard" way of doing this? \n works for new line on windows servers right?

  • #15
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Use your tab key to lay the code out well. It'll take a while to get used to it, but it helps you from making silly errors as you can notice them much easier.

    example
    PHP Code:
    <?php
    if($blah == 'foo'){
    do 
    this
    if($this != 'ooh'){
    dont do that
    }else{
    do 
    that instead
    }}else{
    do 
    that
    }
    if(
    $someothervar == 'bar'){
    do 
    this
    else{
    do 
    that
    }
    ?>
    If that was formatted whilst you write it, you'd notice there's a curly brace missing straight away.
    PHP Code:
    <?php
    if($blah == 'foo'){
        do 
    this
        
    if($this != 'ooh'){
            
    dont do that
        
    }else{
            do 
    that instead
        
    }
    }else{
        do 
    that
    }

    if(
    $someothervar == 'bar'){
        do 
    this
    }else{
        do 
    that
    }
    ?>
    Do you see how much easier the second example is to follow?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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