FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need help fixing my php file





SpellcasterDX
Yes, once more I need help fixing my file. I get a
Code:
Parse error: syntax error, unexpected T_ELSE in /home/spellcas/domains/sdx.frih.net/public_html/boards/registration2.php on line 138


That's the error I get. And this is the file in question:

Quote:
<?
$starttime = microtime();
include("common.php");

$navigation[] = array("name" => "User Registration",
"url" => "$PHP_SELF");
global $EmailConfirm;
global $AllowRegisters;
if ($AllowRegisters)
{

if($userloggedin){
$output = "You are already registered.";
}else{
if ($action == "create")
{
$sql = "SELECT code FROM ".TABLE_SECURITY_CODE." WHERE id = 1";
if($exe = runQuery($sql)){
$row = fetchResultArray($exe);
}

if ($code !== $row[code]) { $err[] = "Incorrect security code"; }
if (!$displayname) { $err[] = "No display name was entered"; }
else
{

if ($action == "create")
{
if (!$displayname) { $err[] = "No display name was entered"; }
else
{
// Check for invalid characters in the displayname
$notallowedchars = "[^a-zA-Z0-9\.\_\+-]";
if (ereg($notallowedchars, $displayname))
{ $err[] = "Your display name contains invalid characters"; }
}
if (!$firstname) { $err[] = "No first name was entered"; }
if (!$lastname) { $err[] = "No last name was entered"; }
if ($password1 != $password2) { $err[] = "The two passwords do not match. Please re-enter them."; }
if (!$email) { $err[] = "No email address was entered"; }
if (!$security) { $err[] = "The security code entered is incorrect. Please re-enter it."; }
if (!$_POST['tos']) { $err[] = "You Did Not Agree To The Terms Of Service And Therefore Cannot Register Until You Do"; }
else
{
$validemail = validEmail($email);
if ($validemail == "invalid-form")
{ $err[] = "Your email address is malformed"; }
if ($validemail == "invalid-mx")
{ $err[] = "Your email address cannot be reached"; }

if (countUserEmails($email) > 0)
{ $err[] = "The email address you supplied is already in use."; }
}
if (!$birthdayyear) { $err[] = "No birthday year was entered"; }
else
{
if (!checkdate($birthdaymonth, $birthdayday, $birthdayyear))
{ $err[] = "The birthday entered was invalid"; }
}

if ($err)
{
// Errors were encountered, stop...
$reason = implode("<BR>\n", $err);
$action = "";
}
else
{
// No errors, go ahead
$data[displayname] = $displayname;

$data[firstname] = $firstname;
$data[lastname] = $lastname;
$data[email] = $email;
$data[country] = $country;
$data[birthday] = mkTime(0, 0, 0, $birthdaymonth, $birthdayday, $birthdayyear);
$data[gender] = $gender;
$data[ipaddress] = $REMOTE_ADDR;
$data[password1] = $password1;
$data[password2] = $password2;
$data[security] = $security;


// print_r($data);

$user = createUser($data);

if ($user)
{
// User creation worked
if ($EmailConfirm)
{
$output = "Thank you. Your account has been created.\n"
."<P>\n"
."Login information has been emailed to your supplied email \n"
."address, $email.\n"
."<P>\n"
.makeLink($returnurl, "Continue using $DiscoBoardName");
}
if (!$EmailConfirm)
{
$output = "Thank you. Your account has been created.\n"
."<P>\n"
."Here is your account information:<BR><BR>"
."<B>Username: </B>".$displayname."<BR>"
."<B>Password: </B>".$user
."<P>"
.makeLink($returnurl, "Continue using $DiscoBoardName");
}
}
}
}

if (!$action)
{
if ($reason)
{
$reasonoutput = "<B CLASS='red'>".$reason."</B>\n"
."<P>\n";
}

$mandatory = "<SPAN CLASS='red'>•</SPAN>";

include("elements/newuser.php");
$output = "Please complete the form below to register to use the system.<BR>\n"
."Required fields are marked: ".$mandatory."<BR>\n"
."<P>\n"
.$reasonoutput
."<FORM ACTION='$PHP_SELF' METHOD=POST>\n"
.inputHidden("action", "create")
.inputHidden("returnurl", $returnurl)
.$userform
."<P>\n"
."<INPUT TYPE=\"SUBMIT\" onClick='this.value = \"Processing... Please wait...\";this.disabled = true;this.form.submit();' VALUE=' Register ' CLASS='button' NAME='Register'>"
."</FORM>\n";
}
}
else
{
$output = "Registrations aren't allowed at the moment. Please try again later.";
}


$output = "<TABLE WIDTH=100% CELLPADDING=20 CELLSPACING=1 BORDER=0>\n"
."<TR><TD CLASS='BoardRowBody'>\n"
." ".str_replace("\n", "\n ", $output)."</TD></TR>\n"
."</TABLE>\n";

$pagecontents = $output;
include("layout.php");
?>
hexkid
SpellcasterDX wrote:
...

That's because you have
Code:
if (something)
{
}
else
{
}
else // line 138
{
}

Indent your code properly.
SpellcasterDX
Erm, so, I replace the lines around line 138 with what you said? Sorry, I'm a complete n00b to php.
Star Wars Fanatic
This part here is wrong:

Code:
if ($reason)
{
$reasonoutput = "<B CLASS='red'>".$reason."</B>\n"
."<P>\n";
}

$mandatory = "<SPAN CLASS='red'>•</SPAN>";

include("elements/newuser.php");
$output = "Please complete the form below to register to use the system.<BR>\n"
."Required fields are marked: ".$mandatory."<BR>\n"
."<P>\n"
.$reasonoutput
."<FORM ACTION='$PHP_SELF' METHOD=POST>\n"
.inputHidden("action", "create")
.inputHidden("returnurl", $returnurl)
.$userform
."<P>\n"
."<INPUT TYPE=\"SUBMIT\" onClick='this.value = \"Processing... Please wait...\";this.disabled = true;this.form.submit();' VALUE=' Register ' CLASS='button' NAME='Register'>"
."</FORM>\n";
}
}
else
{
$output = "Registrations aren't allowed at the moment. Please try again later.";
}


Notice how you have the if portion end, then a bunch of code, then the else portion begins, you need to have the if right next to the else, like this:
Code:

if ($reason)
{
$reasonoutput = "<B CLASS='red'>".$reason."</B>\n"
."<P>\n";
}
else
{
$output = "Registrations aren't allowed at the moment. Please try again later.";
}


What to do with the other code, you would prabably stick it at the end of the if-else statement, or stick it in the if statement itself (between the curly braces).


EDIT:
After further examination, it seems you misplaced a curly brace, here:

Quote:
<?
$starttime = microtime();
include("common.php");

$navigation[] = array("name" => "User Registration",
"url" => "$PHP_SELF");
global $EmailConfirm;
global $AllowRegisters;
if ($AllowRegisters)
{

if($userloggedin){
$output = "You are already registered.";
}else{
if ($action == "create")
{
$sql = "SELECT code FROM ".TABLE_SECURITY_CODE." WHERE id = 1";
if($exe = runQuery($sql)){
$row = fetchResultArray($exe);
}

if ($code !== $row[code]) { $err[] = "Incorrect security code"; }
if (!$displayname) { $err[] = "No display name was entered"; }
else
{

if ($action == "create")
{
if (!$displayname) { $err[] = "No display name was entered"; }
else
{
// Check for invalid characters in the displayname
$notallowedchars = "[^a-zA-Z0-9\.\_\+-]";
if (ereg($notallowedchars, $displayname))
{ $err[] = "Your display name contains invalid characters"; }
}
if (!$firstname) { $err[] = "No first name was entered"; }
if (!$lastname) { $err[] = "No last name was entered"; }
if ($password1 != $password2) { $err[] = "The two passwords do not match. Please re-enter them."; }
if (!$email) { $err[] = "No email address was entered"; }
if (!$security) { $err[] = "The security code entered is incorrect. Please re-enter it."; }
if (!$_POST['tos']) { $err[] = "You Did Not Agree To The Terms Of Service And Therefore Cannot Register Until You Do"; }
else
{
$validemail = validEmail($email);
if ($validemail == "invalid-form")
{ $err[] = "Your email address is malformed"; }
if ($validemail == "invalid-mx")
{ $err[] = "Your email address cannot be reached"; }

if (countUserEmails($email) > 0)
{ $err[] = "The email address you supplied is already in use."; }
}
if (!$birthdayyear) { $err[] = "No birthday year was entered"; }
else
{
if (!checkdate($birthdaymonth, $birthdayday, $birthdayyear))
{ $err[] = "The birthday entered was invalid"; }
}

if ($err)
{
// Errors were encountered, stop...
$reason = implode("<BR>\n", $err);
$action = "";
}
else
{
// No errors, go ahead
$data[displayname] = $displayname;

$data[firstname] = $firstname;
$data[lastname] = $lastname;
$data[email] = $email;
$data[country] = $country;
$data[birthday] = mkTime(0, 0, 0, $birthdaymonth, $birthdayday, $birthdayyear);
$data[gender] = $gender;
$data[ipaddress] = $REMOTE_ADDR;
$data[password1] = $password1;
$data[password2] = $password2;
$data[security] = $security;


// print_r($data);

$user = createUser($data);

if ($user)
{
// User creation worked
if ($EmailConfirm)
{
$output = "Thank you. Your account has been created.\n"
."<P>\n"
."Login information has been emailed to your supplied email \n"
."address, $email.\n"
."<P>\n"
.makeLink($returnurl, "Continue using $DiscoBoardName");
}
if (!$EmailConfirm)
{
$output = "Thank you. Your account has been created.\n"
."<P>\n"
."Here is your account information:<BR><BR>"
."<B>Username: </B>".$displayname."<BR>"
."<B>Password: </B>".$user
."<P>"
.makeLink($returnurl, "Continue using $DiscoBoardName");
}
}
}
}

if (!$action)
{
if ($reason)
{
$reasonoutput = "<B CLASS='red'>".$reason."</B>\n"
."<P>\n";
}


$mandatory = "<SPAN CLASS='red'>•</SPAN>";

include("elements/newuser.php");
$output = "Please complete the form below to register to use the system.<BR>\n"
."Required fields are marked: ".$mandatory."<BR>\n"
."<P>\n"
.$reasonoutput
."<FORM ACTION='$PHP_SELF' METHOD=POST>\n"
.inputHidden("action", "create")
.inputHidden("returnurl", $returnurl)
.$userform
."<P>\n"
."<INPUT TYPE=\"SUBMIT\" onClick='this.value = \"Processing... Please wait...\";this.disabled = true;this.form.submit();' VALUE=' Register ' CLASS='button' NAME='Register'>"
."</FORM>\n";
}
}
else
{
$output = "Registrations aren't allowed at the moment. Please try again later.";
}


$output = "<TABLE WIDTH=100% CELLPADDING=20 CELLSPACING=1 BORDER=0>\n"
."<TR><TD CLASS='BoardRowBody'>\n"
." ".str_replace("\n", "\n ", $output)."</TD></TR>\n"
."</TABLE>\n";

$pagecontents = $output;
include("layout.php");
?>


Just delete the ending curly brace, and that error is fixed, however another parse error occurs:
Quote:
Parse error: parse error, unexpected $end in /home/spellcas/domains/sdx.frih.net/public_html/boards/registration2.php on line 151


Which is the last line, though that may be just because I was calling the page incorrectly. Although why it didn't encounter an error when it tried to include common.php and layout.php, I don't know.
kv
Here you go
Code:

<?
$starttime = microtime();
include("common.php");

$navigation[] = array("name" => "User Registration",
                      "url" => "$PHP_SELF");
global $EmailConfirm;
global $AllowRegisters;
if ($AllowRegisters)
{

   if($userloggedin)
   {
      $output = "You are already registered.";
   }
   else
   {
      if ($action == "create")
      {
         $sql = "SELECT code FROM ".TABLE_SECURITY_CODE." WHERE id = 1";
         if($exe = runQuery($sql))
         {
            $row = fetchResultArray($exe);
         }

         if ($code !== $row[ code ])
         {
            $err[] = "Incorrect security code";
         }
         if (!$displayname)
         {
            $err[] = "No display name was entered";
         }
         else
         {

            if ($action == "create")
            {
               if (!$displayname)
               {
                  $err[] = "No display name was entered";
               }
               else
               {
                  // Check for invalid characters in the displayname
                  $notallowedchars = "[^a-zA-Z0-9\.\_\+-]";
                  if (ereg($notallowedchars, $displayname))
                  {
                     $err[] = "Your display name contains invalid characters";
                  }
               }
               if (!$firstname)
               {
                  $err[] = "No first name was entered";
               }
               if (!$lastname)
               {
                  $err[] = "No last name was entered";
               }
               if ($password1 != $password2)
               {
                  $err[] = "The two passwords do not match. Please re-enter them.";
               }
               if (!$email)
               {
                  $err[] = "No email address was entered";
               }
               if (!$security)
               {
                  $err[] = "The security code entered is incorrect. Please re-enter it.";
               }
               if (!$_POST['tos'])
               {
                  $err[] = "You Did Not Agree To The Terms Of Service And Therefore Cannot Register Until You Do";
               }
               else
               {
                  $validemail = validEmail($email);
                  if ($validemail == "invalid-form")
                  {
                     $err[] = "Your email address is malformed";
                  }
                  if ($validemail == "invalid-mx")
                  {
                     $err[] = "Your email address cannot be reached";
                  }

                  if (countUserEmails($email) > 0)
                  {
                     $err[] = "The email address you supplied is already in use.";
                  }
               }
               if (!$birthdayyear)
               {
                  $err[] = "No birthday year was entered";
               }
               else
               {
                  if (!checkdate($birthdaymonth, $birthdayday, $birthdayyear))
                  {
                     $err[] = "The birthday entered was invalid";
                  }
               }

               if ($err)
               {
                  // Errors were encountered, stop...
                  $reason = implode("<BR>\n", $err);
                  $action = "";
               }
               else
               {
                  // No errors, go ahead
                  $data[displayname] = $displayname;

                  $data[firstname] = $firstname;
                  $data[lastname] = $lastname;
                  $data[email] = $email;
                  $data[country] = $country;
                  $data[birthday] = mkTime(0, 0, 0, $birthdaymonth, $birthdayday, $birthdayyear);
                  $data[gender] = $gender;
                  $data[ipaddress] = $REMOTE_ADDR;
                  $data[password1] = $password1;
                  $data[password2] = $password2;
                  $data[security] = $security;


                  // print_r($data);

                  $user = createUser($data);

                  if ($user)
                  {
                     // User creation worked
                     if ($EmailConfirm)
                     {
                        $output = "Thank you. Your account has been created.\n"
                                  ."<P>\n"
                                  ."Login information has been emailed to your supplied email \n"
                                  ."address, $email.\n"
                                  ."<P>\n"
                                  .makeLink($returnurl, "Continue using $DiscoBoardName");
                     }
                     if (!$EmailConfirm)
                     {
                        $output = "Thank you. Your account has been created.\n"
                                  ."<P>\n"
                                  ."Here is your account information:<BR><BR>"
                                  ."<B>Username: </B>".$displayname."<BR>"
                                  ."<B>Password: </B>".$user
                                  ."<P>"
                                  .makeLink($returnurl, "Continue using $DiscoBoardName");
                     }
                  }
               }
            }

            if (!$action)
            {
               if ($reason)
               {
                  $reasonoutput = "<B CLASS='red'>".$reason."</B>\n"
                                  ."<P>\n";
               }

               $mandatory = "<SPAN CLASS='red'>•</SPAN>";

               include("elements/newuser.php");
               $output = "Please complete the form below to register to use the system.<BR>\n"
                         ."Required fields are marked: ".$mandatory."<BR>\n"
                         ."<P>\n"
                         .$reasonoutput
                         ."<FORM ACTION='$PHP_SELF' METHOD=POST>\n"
                         .inputHidden("action", "create")
                         .inputHidden("returnurl", $returnurl)
                         .$userform
                         ."<P>\n"
                         ."<INPUT TYPE=\"SUBMIT\" onClick='this.value = \"Processing... Please wait...\";this.disabled = true;this.form.submit();' VALUE=' Register ' CLASS='button' NAME='Register'>"
                         ."</FORM>\n";
            }
         }

      }
   }
}
else
{
   $output = "Registrations aren't allowed at the moment. Please try again later.";
}

$output = "<TABLE WIDTH=100% CELLPADDING=20 CELLSPACING=1 BORDER=0>\n"
          ."<TR><TD CLASS='BoardRowBody'>\n"
          ." ".str_replace("\n", "\n ", $output)."</TD></TR>\n"
          ."</TABLE>\n";

$pagecontents = $output;
include("layout.php");
?>
Star Wars Fanatic
Ah, good idea, I thought of doing it myself, but decided not to, well, SpellcasterDX misplaced a curly brace no matter what, lol.
SpellcasterDX
Thanks a bunch, kv! Very Happy
Related topics
I need help setting up a default index file?
Uploading a .php file! NEED HELP thanks
Need help with subdomains of my hosting account!
Contact form
Need help with php
Need help with PHP
#Paying 30 + frih$ to fix my javascript! Help! Fast!#
need help with a script for vb its not to hard i think
I need help yet again
Need help: Error in Wordpress file
PHP issues >.>
need help on PHP or HTML...
Need help on PHP programming....
need help in a simple php register script based on flat file
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.