Parse error: syntax error, unexpected $end in /register.php on line 2

Discussion in 'PHP' started by Hontoir, Feb 27, 2008.

  1. #1
    Hi Guys could do with some help!! Im new and am having a little trouble finding the error, have looked on previous threads and have checked all the "}"

    <?php if(isset($_POST['Submit']))
    {
    //NEED TO CHECK IF FIELDS ARE FILLED IN
    if( empty($_POST['name']) && (empty($_POST['email'])))
    {
    header("Location:Messages.php?msg=3");
    exit();
    }

    if( empty($_POST['pw1']) && (empty($_POST['pw2'])))
    {
    header( "Location:Messages.php?msg=4" );
    exit();
    }

    $name=$_POST['name'];
    $email=$_POST['email'];

    $pw1=$_POST['pw1'];
    $pw2=$_POST['pw2'];

    if("$pw1" !== "$pw2" )
    {
    header( "Location:Messages.php?msg=5" );
    exit();
    }

    $ip = $_SERVER['REMOTE_ADDR'];

    //connect to the db server , check if uname exist
    include('config.php');

    $query=("Select * from user where uname='$name'");
    $result= mysql_query($query);
    $num= mysql_num_rows($result);

    if ($num > 0)
    {//Username already exist
    header( "Location:Messages.php?msg=6" );
    exit();
    }else
    {
    //if username does not exist insert user details
    $query=( "INSERT INTO user (uname, pw,email,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email',NOW(),'$ip','Normal')");

    if (@mysql_query ($query))
    {
    header("location:login.php?reg=1");
    exit;
    }
    }

    mysql_close();
    }
    ?>
     
    Hontoir, Feb 27, 2008 IP
  2. bpasc95

    bpasc95 Active Member

    Messages:
    196
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Try taking this part (lines 1-3):
    <?php if(isset($_POST['Submit']))
    {
    //NEED TO CHECK IF FIELDS ARE FILLED IN
    if( empty($_POST['name']) && (empty($_POST['email'])))
    PHP:
    and replacing it with this:

    <?php 
    if(array_key_exists('Submit', $_POST))
    {
    	//NEED TO CHECK IF FIELDS ARE FILLED IN
    	if( empty($_POST['name']) && (empty($_POST['email'])))
    PHP:
    That should resolve your issue.
    -Bing
     
    bpasc95, Feb 27, 2008 IP
  3. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #3
    this error means a "{" is not closed, try putting a close "}"
    on line 9..
     
    bartolay13, Feb 27, 2008 IP
  4. Hontoir

    Hontoir Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There is a close "}" supplied for line 2 at the end of the code.
     
    Hontoir, Feb 27, 2008 IP
  5. Hontoir

    Hontoir Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <?php
    if(array_key_exists('Submit', $_POST))
    {
        //NEED TO CHECK IF FIELDS ARE FILLED IN
        if( empty($_POST['name']) && (empty($_POST['email'])))
         {
              header("Location:Messages.php?msg=3"); 
              exit();
         }
    	 
         if( empty($_POST['pw1']) && (empty($_POST['pw2'])))
    	 {
              header( "Location:Messages.php?msg=4" ); 
              exit();
         }
    	 
         $name=$_POST['name'];
         $email=$_POST['email'];
    
         $pw1=$_POST['pw1'];
         $pw2=$_POST['pw2'];
    
         if("$pw1" !== "$pw2"  )
    	 {
              header( "Location:Messages.php?msg=5" ); 
              exit();
         }
    	 
         $ip = $_SERVER['REMOTE_ADDR'];
    
         //connect to the db server , check if uname exist
         include('config.php');
    
         $query=("Select * from user where uname='$name'");
         $result= mysql_query($query); 
         $num= mysql_num_rows($result);
    
         if ($num > 0) 
    	 {//Username already exist
              header( "Location:Messages.php?msg=6" ); 
              exit();
         }else
    	 {
              //if username does not exist insert user details
              $query=( "INSERT INTO user (uname, pw,email,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email',NOW(),'$ip','Normal')");
    
              if (@mysql_query ($query)) 
    		  {
                   header("location:login.php?reg=1");
                   exit;
              }
         }
    	 
         mysql_close();
    }
    ?>
    
    PHP:
    I have edited the code so that it now looks like the above.
    Now error message says

    Parse error: syntax error, unexpected '{' in /register.php on line 1

    :S

    So now there is one too many "{"??
     
    Hontoir, Feb 27, 2008 IP
  6. Hontoir

    Hontoir Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Now all Resolved
     
    Hontoir, Feb 27, 2008 IP
  7. Hontoir

    Hontoir Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    <?php
    session_start();
    
    if(array_key_exists('reg', $_GET))
    {
    	$reg=$_GET['reg'];
    }else
    {
    	$reg="";
    }
    
    if($reg==1)
    {
    $msg1="<font color=\"#FF0000\"><b>Your details have been added, please login</b></font>";
    }
    if($reg==2)
    {
    $msg1="<font color=\"#FF0000\"><b>You have been successfully logged out.</b></font>";
    }
    
    
    if(array_key_exists('Submit', $_POST))
    {
    	if( empty($_POST['uname']) && (empty($_POST['upass'])))
    	{
    		header( "Location:Messages.php?msg=1" ); 
    		exit();
    	}
    
    	//transfer to shorter var
    		$n=$_POST['uname'];
    		$p=$_POST['upass'];
    
    	//connect to db
    	include('config.php');
    	$query="select * from user where uname='$n'  and pw='$p' ";
    	$result=mysql_query($query);
    	
    	$num=mysql_num_rows($result);
    	if($num>0 )
    	{
    		//put in session vars
    
    		$mytime=time();
    		$mytime=date("H:i:s A",$mytime);
    		$_SESSION['time'] = $mytime;
    		$_SESSION['status'] = 'logged';
    		$_SESSION['username'] = $n;
    		//goto next page
    		header("location:welcome.php");
    		exit();
    	}else
    	{
    		$_SESSION['status'] = 'not logged';
    		header( "Location:Messages.php?msg=2" ); 
    		exit();
    
    	}
    }
    ?>
    
    PHP:
    Another one with exactly the same error message. I have changed the coding to the example given above by byPasc95
     
    Hontoir, Feb 27, 2008 IP
  8. Hontoir

    Hontoir Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    TTT. Anybody??
     
    Hontoir, Feb 28, 2008 IP
  9. dria

    dria Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    [h=2]Can anyone help....[/h]
    My screen reads Parse error T_ENDIF in ..... on line 172...I think its in here

    <?php if ($this->countModules('user4') or $this->countModules('user5') or $this->countModules('user6') or $this->countModules('user7')) : ?>
    <div id="bottom">
    <div id="bottommodules" class="spacer<?php echo $bottommods_width; ?>">
    <?php if ($this->countModules('user4')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user4" style="rounded" />
    </div>
    <?php endif; ?>
    <?php if ($this->countModules('user5')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user5" style="rounded" />
    </div>
    <?php endif; ?>
    <?php if ($this->countModules('user6')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user6" style="rounded" />
    </div>
    <?php endif; ?>
    <?php if ($this->countModules('user7')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user7" style="rounded" />
    </div>
    <?php endif; ?>
    </div>
    </div>
    <?php endif; ?>
     
    dria, May 24, 2012 IP
  10. dria

    dria Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    [h=2]Can anyone help....[/h]
    My screen reads Parse error T_ENDIF in ..... on line 172...I think its in here

    <?php if ($this->countModules('user4') or $this->countModules('user5') or $this->countModules('user6') or $this->countModules('user7')) : ?>
    <div id="bottom">
    <div id="bottommodules" class="spacer<?php echo $bottommods_width; ?>">
    <?php if ($this->countModules('user4')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user4" style="rounded" />
    </div>
    <?php endif; ?>
    <?php if ($this->countModules('user5')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user5" style="rounded" />
    </div>
    <?php endif; ?>
    <?php if ($this->countModules('user6')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user6" style="rounded" />
    </div>
    <?php endif; ?>
    <?php if ($this->countModules('user7')) : ?>
    <div class="block">
    <jdoc:include type="modules" name="user7" style="rounded" />
    </div>
    <?php endif; ?>
    </div>
    </div>
    <?php endif; ?>
     
    dria, May 25, 2012 IP