Results 1 to 22 of 22
  1. #1
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104

    Random PHP Parse Error

    Here's my script; it gets registration info, links to itself w/ a GET variable, which triggers the page to not get info but to check if the given info is valid and then either say it's valid or re-show the form:

    Code:
    <html>
    <head>
    <title>CGP-RPG Registration</title>
    <?php include("/rpg/include/RPGhead.inc"); ?>
    </head>
    <body>
    <?php include("/rpg/include/RPGupper.inc"); ?>
    
    <? php
    $formCode = 
    "<form method=/"POST/" action=/"register.php?reg=true/">/n/r
    RPG Name:&nbsp;<input type=/"text/" size=/"12/" name=/"memName/" value=/"$memName/">(Up to 12 characters long; Numbers, letters, and underscores(_) only)<br />/n/r
    Password:&nbsp;<input type=/"password/" size=/"12/" name=/"passWord/">(4-12 characters long; Numbers and letters only)<br />/n/r
    Repeat Password:&nbsp;<input type=/"password/" size=/"12/" name=/"passWordRep/"><br />/n/r
    Email Address:&nbsp;<input type=/"text/" size=/"30/" name=/"userEmail/" value=/"$userEmail/">(Must be a valid email address, such as: [email protected])<br />/n/r
    <input type=/"submit/" value=/"Submit!/"><br />/n/r
    </form>/n/r"
    
     if (!isSet($reg)) { 
    ?>
    <blockquote>To register for CGRPG, simply fill out the form below and click the "Submit" button.  Please note that your email address will not be publicized, 
    and that only Falco1199 will even be able to see it.  It is only used for sending emails about new RPG quests or features, and will be used VERY infrequently.</blockquote><br /><br />
    <?php print($formCode); ?>
    <?php 
    } else { 
    
     if (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$memName) && strlen($memName) <= 12 && strlen($memName) < 0)
      {
      if (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$passWord) && strlen($password) <= 12 && strlen($password) >= 4)
       {
       if ($passWord === $passWordRep)
        {
        if (ereg('^.\+@.\+\..\+$',$userEmail))
         {
         /* Here's what happens with a good form (much more will be here later) */ print("Form is good!");
         }
        else
         {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your email address isn't valid.</span>
    print($formCode);
    <?php
         }
       else
        {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your passwords don't match.</span>
    print($formCode);
    <?php
        }
      else
       {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your password isn't valid.</span>
    print($formCode);
    <?php
       }
     else
      {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your team name isn't valid.</span>
    print($formCode);
    <?php
      }
    ?>
    
    <?php include("/rpg/include/RPGlower.inc"); ?>
    </body>
    </html>
    And I get this error:

    Parse error: parse error in (server path to site here)/rpg/register.php on line 10

    Does anyone see my problem? It seems to be just a variable assignment...
    :-D

  2. #2
    Join Date
    May 2001
    Location
    Dayton, Ohio
    Posts
    4,962
    PHP Code:
    $formCode "<form method=\"POST\" action=\"register.php?reg=true\">\n\r
    RPG Name: <input type=\"text\" size=\"12\" name=\"memName\" value=\"
    $memName\">(Up to 12 characters long; Numbers, letters, and underscores(_) only)<br \>\n\r
    Password: <input type=\"password\" size=\"12\" name=\"passWord\">(4-12 characters long; Numbers and letters only)<br \>\n\r
    Repeat Password: <input type=\"password\" size=\"12\" name=\"passWordRep\"><br \>\n\r
    Email Address: <input type=\"text\" size=\"30\" name=\"userEmail\" value=\"
    $userEmail\">(Must be a valid email address, such as: [email][email protected][/email])<br \>\n\r
    <input type=\"submit\" value=\"Submit!\"><br \>\n\r
    <\form>\n\r"

    You use \ not / when you need to use " "'s
    -Mat Sumpter
    Director, Product Engagement
    Penton Media

  3. #3
    Join Date
    May 2001
    Location
    Dayton, Ohio
    Posts
    4,962
    You also forgot the ; at the end of the varible definiton....

    $var = "bleh";
    -Mat Sumpter
    Director, Product Engagement
    Penton Media

  4. #4
    Join Date
    Sep 2002
    Location
    San Francisco, CA
    Posts
    103
    yeah. wrong escape character

    also, you don't want a space in your php opening tag

    <? php

    should be

    <?php

    also missing the ; at the end of that long line...

    if statement nesting looks a bit off too, but I've got to get back to work

    happy coding

  5. #5
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    Alright, thanks a lot!

    Now I get a parse error on line 43, which is the ELSE in the following section:

    Code:
    <span style="COLOR: RED"><b>ERROR!</b> Your email address isn't valid.</span>
    print($formCode); /* line 40 */
    <?php
         }
       else
        {
    Does anyone see this problem??
    :-D

  6. #6
    Join Date
    Jan 2002
    Posts
    360
    Originally posted by Falco1199
    Now I get a parse error on line 43, which is the ELSE in the following section:

    Does anyone see this problem??
    You're using 'print' outside the PHP

    Should be

    PHP Code:
    <span style="COLOR: RED"><b>ERROR!</b> Your email address isn't valid.</span>
    <?php
        
    print($formCode); /* line 40 */
         
    }
       else
        {

  7. #7
    Join Date
    Sep 2002
    Location
    San Francisco, CA
    Posts
    103
    also, as I mentioned before, your nesting is off...

    you have this going on...

    PHP Code:
    if()
    {

    }
    else
    {

    }
    else
    {


    can't have 2 elses

  8. #8
    Join Date
    Jan 2002
    Location
    Ohio
    Posts
    3,139
    Instead of the 2 elses which you really can't do (which is already mentioned) you can do:

    PHP Code:

    if () {

    } elseif {

    } else {


    I'm pretty sure this will work as intended.
    Glioblastoma Multiforme (GBM) Brain Cancer Awareness. May is Brain Cancer awareness month. Gray Matters!
    Incurable, 6-18 months prognosis, survivors longer than 3 years less than 1% chance.
    Don't like what I say? Ignore me.

  9. #9
    ... as long as you put another condition to go with the elseif, eg.
    PHP Code:
    if ($x == $y) {

    }
    elseif (
    $x == $z) {

    }
    else {



  10. #10
    Join Date
    Sep 2002
    Location
    San Francisco, CA
    Posts
    103
    I think in fact, he's missing a closing } on one of the outer if statements

    tidy up the code, and it will be clear

  11. #11
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    Alright, I added some close brackets, and thought I had fixed it, but I still get a parse error on line 50.

    Code:
    <html>
    <head>
    <title>CGP-RPG Registration</title>
    <?php include("/home/virtual/cgplatinum.com/var/www/html/rpg/include/RPGhead.inc"); ?>
    </head>
    <body>
    <?php include("/home/virtual/cgplatinum.com/var/www/html/rpg/include/RPGupper.inc"); ?>
    
    <?php
    /* line 10 */ $formCode = 
    "<form method=\"POST\" action=\"register.php?reg=true\">\n\r
    RPG Name:&nbsp;<input type=\"text\" size=\"12\" name=\"memName\" value=\"$memName\">(Up to 12 characters long; Numbers, letters, and underscores(_) only)<br />\n\r
    Password:&nbsp;<input type=\"password\" size=\"12\" name=\"passWord\">(4-12 characters long; Numbers and letters only)<br />\n\r
    Repeat Password:&nbsp;<input type=\"password\" size=\"12\" name=\"passWordRep\"><br />\n\r
    Email Address:&nbsp;<input type=\"text\" size=\"30\" name=\"userEmail\" value=\"$userEmail\">(Must be a valid email address, such as: [email protected])<br />\n\r
    <input type=\"submit\" value=\"Submit!\"><br />\n\r
    </form>\n\r";
    
     if (!isSet($reg)) { 
    /* line 20 */ ?>
    <blockquote>To register for CGRPG, simply fill out the form below and click the "Submit" button.  Please note that your email 
    address will not be publicized, and that only Falco1199 will even be able to see it.  
    It is only used for sending emails about new RPG quests or features, and will be used VERY infrequently.</blockquote><br /><br />
    <?php print($formCode); ?>
    <?php 
    } else { 
    
     if (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$memName) && strlen($memName) <= 12 && strlen($memName) < 0)
      {
      if (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$passWord) && strlen($password) <= 12 && strlen($password) >= 4)
       {
       if ($passWord === $passWordRep) /* line 30 */
        {
        if (ereg('^.\+@.\+\..\+$',$userEmail))
         {
         /* Here's what will happen with a good form */ print("Form is good!");
         }
        else
         {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your email address isn't valid.</span>
    <?php /* line 40 */
    print($formCode);
         } 
        }
       else
        {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your passwords don't match.</span>
    <?php 
    print($formCode)
        }
       }
      else /* line 50 */
       {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your password isn't valid.</span>
    <?php
    print($formCode);
       } 
      }
     else
      {
    ?>
    <span style="COLOR: RED"><b>ERROR!</b> Your team name isn't valid.</span>
    <?php
    print($formCode);
      }
    ?>
    
    <?php include("/home/virtual/cgplatinum.com/var/www/html/rpg/include/RPGlower.inc"); ?>
    </body>
    </html>
    What now?
    :-D

  12. #12
    Join Date
    Jan 2002
    Posts
    360
    you're missing a semi-colon on the print($formCode) before where you have marked as line 50

  13. #13
    Join Date
    Jan 2002
    Posts
    360
    Here.. try this

    Code:
    <html>
    <head>
    <title>CGP-RPG Registration</title>
    <?php include("/home/virtual/cgplatinum.com/var/www/html/rpg/include/RPGhead.inc"); ?>
    </head>
    <body>
    <?php
    
    include("/home/virtual/cgplatinum.com/var/www/html/rpg/include/RPGupper.inc");
    
    $formCode =
    "<form method=\"POST\" action=\"register.php?reg=true\">\n\r
    RPG Name:*<input type=\"text\" size=\"12\" name=\"memName\" value=\"$memName\">(Up to 12 characters long; Numbers, letters, and underscores(_) only)<br />\n\r
    Password:*<input type=\"password\" size=\"12\" name=\"passWord\">(4-12 characters long; Numbers and letters only)<br />\n\r
    Repeat Password:*<input type=\"password\" size=\"12\" name=\"passWordRep\"><br />\n\r
    Email Address:*<input type=\"text\" size=\"30\" name=\"userEmail\" value=\"$userEmail\">(Must be a valid email address, such as: [email protected])<br />\n\r
    <input type=\"submit\" value=\"Submit!\"><br />\n\r
    </form>\n\r";
    
     if (!isSet($reg)) {
    	?>
    	<blockquote>To register for CGRPG, simply fill out the form below and click the "Submit" button.  Please note that your email
    	address will not be publicized, and that only Falco1199 will even be able to see it. 
    	It is only used for sending emails about new RPG quests or features, and will be used VERY infrequently.</blockquote><br /><br />
    	<?php print($formCode);
    	
    } else {
    
     	if (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$memName) && (strlen($memName) <= 12) && (strlen($memName) < 0))
    	{
    		if (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$passWord) && (strlen($password) <= 12) && (strlen($password) >= 4))
    		{
    			if ($passWord == $passWordRep)
    			{
    				if (ereg('^.\+@.\+\..\+$',$userEmail))
    				{
    					print("Form is good!"); // Here's what will happen with a good form
    				}
    				else
    				{ ?>
    					<span style="COLOR: RED"><b>ERROR!</b> Your email address isn't valid.</span>
    					<?php
    					print($formCode);
    				}
    			}
    			else
    			{
    				?>
    				<span style="COLOR: RED"><b>ERROR!</b> Your passwords don't match.</span>
    				<?php
    				print($formCode);
    			}
    		}
    		else
    		{
    			?>
    			<span style="COLOR: RED"><b>ERROR!</b> Your password isn't valid.</span>
    			<?php
    			print($formCode);
    		}
    	}
    	else
    	{
    		?>
    		<span style="COLOR: RED"><b>ERROR!</b> Your team name isn't valid.</span>
    		<?php
    		print($formCode);
    	}
    }
    include("/home/virtual/cgplatinum.com/var/www/html/rpg/include/RPGlower.inc");
    ?>
    </body>
    </html>
    Last edited by akuo; 09-28-2002 at 09:09 PM.

  14. #14
    Join Date
    Jan 2002
    Posts
    360
    You might also want to check your capitalization, I notice you used $passWord *and* $password...

  15. #15
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    Where does it say "password"? They all look like "passWord" to me.
    :-D

  16. #16
    Join Date
    Jan 2002
    Posts
    360
    if (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$passWord) && (strlen($password) <= 12) && (strlen($password) >= 4))

    I wasn't sure if it was intentional, so I left it in my code sample

  17. #17
    Join Date
    Jan 2002
    Posts
    360
    did the code i posted work out for you?

  18. #18
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    The problems I had are solved, but a new one has arisen. My regexps don't seem to be functioning properly; I typed in the username "this", password "this", passwordrep "this" and email "[email protected]" and I got the I programmed the script to write when the username was incorrect. Does anyone see the problem?

    BTW, I edited the passWord variables so that they're all passWord.
    :-D

  19. #19
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    No one sees a problem with the regexps? Then why am I getting this error message? BTW, you can still see the page at
    www.cgplatinum.com/rpg/register.php

    ?
    :-D

  20. #20
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    OK, I hate to bump this AGAIN, but I'm changing my level of desperation.

    Is the reason no one's responded that they're correct? Could someone look at my regexps, and tell if they're wrong OR not, even if they don't have a possible solution?

    ???
    :-D

  21. #21
    Join Date
    Apr 2002
    Location
    Cornfield
    Posts
    131
    (ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$memName) && (strlen($memName) <= 12) && (strlen($memName) < 0))

    Read that again....
    Pretty impossible for a strlen to be LESS than 0. You need to change that last check.

    Also, I think it's better coding practice (IMHO) to test for negatives, so you tell immediately from looking at the code what error message is outputted for each failed test eg.
    PHP Code:
    if (!ereg('^[[:upper:][:lower:][:alnum:]_]\+$',$memName) || (strlen($memName) > 12) || (strlen($memName) < 0))
    {
           
    // error stuff here
    }
    else 
    {
           
    // continue on with your merry life

    Fire extinguisher extraordinare
    -------------------------------
    FastServers.Net NOC Admin

  22. #22
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    OH thanks!
    :-D

Posting Permissions

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