SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unexpected T_ELSE

    I was reading through one of Kevin Yanks articles (the one about managing users), and I was fiddeling around with some of the code, and I got the following error:

    Parse error: parse error, unexpected T_ELSE in /home/virtual/site11/fst/var/www/html/practice/xdesigns/register.php on line 92

    The snippet of code that deals with this is as follows:
    PHP Code:
    else:
     
     
    dbConnect('star-craftx_com');
    //make sure the required fields were filled out
    if ($username=="" or $password=="" $email=="") {
     
    error("One or more of the required fields were left blank.\\n".
      
    "Please fill them in and try again.");

    I read back through the article, and everything seems as if everything's the way it's supposed to be.

  2. #2
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you forgot the or between $password=="" $email==""

    It's better to use || instead of or as well.
    Mike
    It's not who I am underneath, but what I do that defines me.

  3. #3
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the || thing, I'll start using that

    But I still get the same error..
    PHP Code:
    else:
    dbConnect('star-craftx_com');
    //make sure the required fields were filled out
    if ($username=="" || $password=="" || $email=="") {
     
    error("One or more of the required fields were left blank.\\n".
      
    "Please fill them in and try again.");


  4. #4
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is an endif; afterwards, right?

    I can't see the error here, perhaps a few more lines above and below?
    Mike
    It's not who I am underneath, but what I do that defines me.

  5. #5
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Directly above that code is HTML, so I'll post the stuff above that:
    PHP Code:
    <?php //register.php
    include("common.php");
    include(
    "db.php");
    if (!isset(
    $submit));
     
    //display signup form
    ?>
    ===========HTML RIGHT HERE============
    <?php
    else:
    dbConnect('star-craftx_com');
    //make sure the required fields were filled out
    if ($username=="" || $password=="" || $email=="") {
     
    error("One or more of the required fields were left blank.\\n".
      
    "Please fill them in and try again.");
    }
    //check to see if user has already submitted same username
    //same with email address
    $sql "SELECT COUNT(*) FROM design_users WHERE username = '$username'";
    $result mysql_query($sql);
     if (!
    result) {
      
    error("A database error has occured while processing your ".
      
    "submission. [url=file://\nif]\\nif[/url] this error continues, please <a href="maito:koomann@star-craftx.com">contact me</a>");
    }
    if (@
    mysql_result($result,0,0)>0) {
     
    error("A user already exists with your chosen Username.\\n".
      
    "Please use a different username.");
    }
    //if they already used the same email address
    $sql "SELECT COUNT(*) FROM design_users WHERE email = '$email'";
    $result mysql_query($sql);
     if (!
    result) {
      
    error("A database error has occured while processing your ".
      
    "submission. [url=file://\nif]\\nif[/url] this error continues, please <a href="maito:koomann@star-craftx.com">contact me</a>");
    }
    if (@
    mysql_result($result,0,0)>0) {
     
    error("A user already exists with your chosen email address.\\n".
      
    "Please use a different email address.");
    }
    //Finally, insert the data in to the MySQL database.
    $sql "INSERT INTO design_users SET
     username='
    $username',
     password='
    $password',
     email='
    $email',
     aim='
    $aim',
     icq='
    $aim',
     msn='
    $msn',
     date_joined=CURDATE,
     age='
    $age',
     interests='
    $interests',
     job='
    $job',
     website='
    $website',
     websiteurl='
    $websiteurl',
     websitedescription='
    $websitedescription'";
    if (!
    mysql_query($sql))
     
    error("An internal error has occurred in processing your ".
      
    "submission.\\nIf this message continues after you try again, please <a href="mailto:koomann@star-craftx.com">contact me</a>.");
    ?>

  6. #6
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    if (!isset($submit));
    //display signup form

    should be

    if (!isset($submit)) {
    //display signup form

    and change

    else:
    dbConnect('star-craftx_com');
    //make sure the required fields were filled out

    to

    } else {
    dbConnect('star-craftx_com');
    //make sure the required fields were filled out
    }

    Mike
    It's not who I am underneath, but what I do that defines me.

  7. #7
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I came to almost the same answer after fiddeling around with it a little bit

    But when I run the page, I get the message box error saying that I didn't fill out the form. For some reason, right when you go to the page, it submits it, even when you haven't click anything....
    www.star-craftx.com/pracitce/xdesigns/register.php

  8. #8
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, it's almost working fine now.

    But if you take a look at the HTML forms, I only want it so that only the first 3 fields NEED to be filled out, the rest are optional. But when you fill out the form (even completely) and click Join, you get the message box, and it sends you back.

  9. #9
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is the form set to POST?

    PHP Code:
    if ( $_POST['username'] == "" || $_POST['password'] == "" || $_POST['email'] == ""  ) {
    error("One or more of the required fields were left blank. \n Please fill them in and try again." );

    Most of the articles on SP are now outdated for things like register globals, which is what's causing this problem.
    Mike
    It's not who I am underneath, but what I do that defines me.

  10. #10
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you (again) for that, but I've figured out (by using different error messages) that the problem deals with this part of the script:
    PHP Code:
    $sql "INSERT INTO design_users SET
     username='
    $username',
     password='
    $password',
     email='
    $email',
     aim='
    $aim',
     icq='
    $icq',
     msn='
    $msn',
     date_joined=CURDATE,
     age='
    $age',
     interests='
    $interests',
     job='
    $job',
     website='
    $website',
     websiteurl='
    $websiteurl',
     websitedescription='
    $websitedescription'";
    if (!
    mysql_query($sql))
     
    error("An internal error has occurred in processing your ".
      
    "submission.\\nIf this message continues after you try again, please email me at [email=koomann@star-craftx.com]koomann@star-craftx.com[/email]");


  11. #11
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hold on, a friend told me I had the wrong syntax, that it needed to look like this:
    PHP Code:
    $sql "INSERT INTO design_users 
    (username, password, email, aim, icq, msn, date_joined, age, interests, job, website, websiteurl, websitedescription) VALUES ('username', 'password', 'email', 'aim', 'icq', 'msn', 'DATETIME', 'age', 'interests', 'job', 'website', 'websiteurl', 'websitedescription')"

    It seemed to have worked..

  12. #12
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    EDIT you got it, nevermind
    Mike
    It's not who I am underneath, but what I do that defines me.

  13. #13
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


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
  •