Parse error: syntax error, unexpected $end

Discussion in 'PHP' started by abhiN, Feb 15, 2008.

  1. #1
    Hi all

    I m using following code..
    
    <?php
    session_start();
    
    if(!isset($_SESSION['captcha'])){session_register('captcha');}
    $PHP_SELF = $_SERVER['PHP_SELF'];
    $stringa = '';
    $cifre = 5;
    for($i=1;$i<=$cifre;$i++){
    	$letteraOnumero = rand(1,2);
    	if($letteraOnumero == 1){
    		// lettera
    		$lettere = 'ABEFHKMNRVWX';
    		$x = rand(1,11);
    		$lettera = substr($lettere,$x,1);
    		$stringa .= $lettera;
    	} else {
    		$numero = rand(3,7);
    		$stringa .= $numero;
    	}
    }
    $_SESSION['captcha'] = $stringa;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <link rel="stylesheet" type="text/css" href="css/styles.css" />
    </head>
    <body>
    <table width="100" height="54" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" id="Table_01">
      <tr>
        <td height="39"  align="left" valign="top" class="imagesstyle"><h1 class="style2"><img src="3EImages/dot3E.jpg" alt="" width="29" height="29" align="left" class="imagesstyle" />General Enquiry<br />
       </h1>
       <td height="39"  valign="top" style="padding-top: 5px"><a href="http://www.3esolutionsindia.com/" target="_blank">Home</a></td>
       </td>
      </tr>
      <tr>
        <td  align="left" valign="top" class="tableDetail"><p><img src="3EImages/ContactUs/Enquiry.jpg" width="170" height="124" align="right" class="imgbrdr" /><strong>Thanks for showing interest in  3E Solutions.</strong> <br />
                <br />
    Kindly fill all the required  fields. We will get in touch with you within 24 hours.</p>
          <p>&nbsp;</p>
    	<form id="captchaform" action="enquiry.php" method="post" style="width:300px;">
            <p align="right"> <label>
            *Name:
            <input type="text" name="name" id="name" size="30"/>
            </label></p>
            <p align="right">*Email Address:
              <label>
              <input type="text" name="email" id="email" size="30" />
              </label>
            </p>
            <p align="right">Phone No:
              <label>
              <input type="text" name="phone" id="phone" size="30" />
              </label>
            </p>
            <p align="right" style="">Interseted in:
              <label>
              <textarea name="interested" cols="30" rows="6" wrap="physical" id="interested">
              </textarea>
              </label>
    		</p>
    		<p align="right">
    				<div id="captcha">
    				<p align="right"><img src="captcha.php" />&nbsp;&nbsp;</p>
    				<p align="right"><label for="code">*Enter Code: </label>
    				<input type="text" name="code" id="code" size="30" /></p>
    				</div>
    				</p>
    				<p align="right"><input type="submit" name="button" id="button" value="Submit" style="font-size:small;color: black;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
    		</form>
          </td>
      </tr>
      </table>
    </body>
    </html>
    
    
    PHP:
    and getting arror as--
    Parse error: syntax error, unexpected $end in /home/esolutio/public_html/enquirycaptcha.php on line 1


    i m not getting where is the problem..
    plz reply.
     
    abhiN, Feb 15, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I copied this into my own file and I am getting no such error.

    sitexero.net/test/test.php
     
    zerxer, Feb 15, 2008 IP
  3. abhiN

    abhiN Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Actually the error occures when i upload this page on the web..

    when i run on my pc it'll not give any error..

    why happning so..
     
    abhiN, Feb 16, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    
    [root@node data]# php -l abhiN.php
    No syntax errors detected in abhiN.php
    
    Code (markup):
    This leads me to believe there is something wrong with your PHP installation. Plus, line one opens the PHP tag, and nothing else.

    Jay
     
    jayshah, Feb 16, 2008 IP
  5. abhiN

    abhiN Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i've changed my php locatio as--

    
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="css/styles.css" />
    </head>
    <body>
    
    <?php
    session_start();
    
    if(!isset($_SESSION['captcha']))
    {
    	session_register('captcha');
    }
    
    $PHP_SELF = $_SERVER['PHP_SELF'];
    $stringa = '';
    $cifre = 5;
    for($i=1;$i<=$cifre;$i++)
    {
    	$letteraOnumero = rand(1,2);
    	if($letteraOnumero == 1)
    	{
    		// lettera
    		$lettere = 'ABEFHKMNRVWX';
    		$x = rand(1,11);
    		$lettera = substr($lettere,$x,1);
    		$stringa .= $lettera;
    	}
    	else
    	{
    		$numero = rand(3,7);
    		$stringa .= $numero;
    	}
    }
    $_SESSION['captcha'] = $stringa;
    
    ?>
    
    <table width="100" height="54" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" id="Table_01">
      <tr>
        <td height="39" align="left" valign="top" class="imagesstyle"><h1 class="style2"><img src="3EImages/dot3E.jpg" alt="" width="29" height="29" align="left" class="imagesstyle" />Contact Us<br />
       </h1>
       <td height="39"  valign="top" style="padding-top: 5px"><a href="http://www.3esolutionsindia.com/" target="_blank">Home</a></td>
       </td>
      </tr>
      <tr>
        <td  align="left" valign="top" class="tableDetail"><p><img src="3EImages/ContactUs/Enquiry.jpg" width="170" height="124" align="right" class="imgbrdr" /><strong>Thanks for showing interest in  3E Solutions.</strong> <br />
                <br />
    Kindly fill all the required  fields. We will get in touch with you within 24 hours.</p>
          <p>&nbsp;</p>
       <form id="captchaform" action="contact.php" method="post" style="width:300px;">
            <p align="right"> <label>
    		        *Name:
    		        <input type="text" name="name" id="name" size="30"/>
    		        </label></p>
    		        <p align="right">*Email Address:
    		          <label>
    		          <input type="text" name="email" id="email" size="30" />
    		          </label>
    		        </p>
    		        <p align="right">Phone No:
    		          <label>
    		          <input type="text" name="phone" id="phone" size="30" />
    		          </label>
    		        </p>
    		        <p align="right" style="">Interseted in:
    		          <label>
    		          <textarea name="interested" cols="30" rows="6" wrap="physical" id="interested">
    		          </textarea>
    		          </label>
    		</p>
    		<p align="right">
    		<div id="captcha">
    		<p align="right"><img src="captcha.php" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
    		<p align="right"><label for="code">*Enter Code: </label>
    		<input type="text" name="code" id="code" size="30" /></p>
    		</div>
    		</p>
    		<p align="right"><input type="submit" name="button" id="button" value="Submit" style="font-size:x-small;color: black;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
    	</form>
          </td>
      </tr>
     </table>
    </body>
    </html>
    
    
    Code (markup):

    then i m getting warning as--

    
    Warning : session_start() [function.session-start]: Cannot send the session cookie already sent by(output started at home/esolutio/public_html/contactuscaptcha.php:3) in  /home/esolutio/public_html/contactuscaptcha.php on line 8
    
    Warning : session_start() [function.session-start]: Cannot send the session cache limiter -headers already sent by(output started at home/esolutio/public_html/contactuscaptcha.php:3) in  /home/esolutio/public_html/contactuscaptcha.php on line 8
    
    Code (markup):

    what about this warning??
    and it'll not displaying the captcha image..

    whats the problem now??

    plz reply..
     
    abhiN, Feb 17, 2008 IP
  6. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #6
    
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="css/styles.css" />
    </head>
    <body>
    
    <?php
    session_start();
    
    PHP:
    You've starting printing HTML, then tried to send the session headers. It's not going to happen. Put

    
    <?php
    session_start();
    ?>
    
    PHP:
    At the very top of that file, and remove it from Line 8.

    Jay
     
    jayshah, Feb 17, 2008 IP
  7. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Obvious error, you're sending headers after content.

    Read up on what this means at: http://php.net/header
     
    Danltn, Feb 17, 2008 IP
  8. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Try opening the brace at the end of the if (isset....... and not including the ;
    instead of
    
    if(!isset($_SESSION['captcha'])){session_register('captcha');}
    
    Code (markup):
    Try
    
    if(!isset($_SESSION['captcha'])){session_register('captcha') {
    
    Code (markup):
     
    Alley Cat, Feb 17, 2008 IP
  9. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #9
    What?! I've pointed out why, above. Don't follow Alley Cat's advice.
     
    jayshah, Feb 17, 2008 IP
  10. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Quite right Jayshah, didn't realise it was an opening brace, actually thought it was an ordinary bracket.
     
    Alley Cat, Feb 17, 2008 IP