954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Parse error: syntax error, unexpected $end

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
   </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> 
            
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>

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.

abhi287
Light Poster
28 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

:) I ran your script and I didn't get any error. Maybe you are getting the error because there is no space after if(!isset($_SESSION['captcha'])){session_register('captcha');}
Replace this line by this.

if(!isset($_SESSION['captcha'])){ session_register('captcha'); }


Cheers,
Naveen

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

unexpected generaly means youve missed a '}' somwhere and php parser has reached the end of the script expecting it get used to error checking
1) get a decent text editor i use textpad which is so so.
2) using your new editor remove parts of code and trial the script until it runs smoothly that way you will narrow down the location of the error.
3) if you find you have messed your script up just (ctrl z)undo it and it will regress to its former state

im fairly new at php but there hasnt been an error that hasnt got passed my 'trial and error' above. hope i helped

cmarkme
Newbie Poster
4 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

ORIGINAL
<?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;
}
}

FIXED

<?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;
}
}

cmarkme
Newbie Poster
4 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

ORIGINAL <?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; } }

FIXED

<?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; } }

That wouldn't fix anything. There is a } at the end which is for 'for loop'. You just closed the 'for loop' after 'if loop'. That would generate an errorParse error: syntax error, unexpected T_ELSE :)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Actually i m getting this error when i upload my page on the web..
insted when i run this on my pc, it won't generate any error..

So what can i do..

plz help..
thnks all...

abhi287
Light Poster
28 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

That's strange! do you have error_reporting turned on on your local system ?

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

I dont know about that..

How to check that??

abhi287
Light Poster
28 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Open php.ini and search for display_errors. If its off, turn it On. Then look for error_reporting. Uncomment this line. error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT .
Or, add ini_set("display_errors","On"); error_reporting(E_ALL); in your script.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

I m still getting the problem..

i've checked php.ini
All the settings are correct..

But it is happing so.. Is there need extra setting while uploading the php..

plz help..
thanks..

abhi287
Light Poster
28 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

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
   </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> 
            
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>

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

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

whats the problem now??

plz reply..

abhi287
Light Poster
28 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

That means you have an echo statemtn of a html tag before session_start(); .

and it'll not displaying the captcha image..


Check this script. Maybe it isn't doing its job.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

You are not allowed to use the <?php ?> tags more than once in you code.
So if you code is like this:

<?php
echo "a";
?>

<?php
echo "b";
?>


This will produce an error because it is used twice.

altosaxplayer88
Newbie Poster
4 posts since Apr 2011
Reputation Points: 5
Solved Threads: 0
 

session_start() should be very top of the file before returning any HTML output and should not have empty line or space between php opening tag and session_start(). Move 'session_start()' before any html tags. Below is the valid format.

<?php
session_start();
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/styles.css" />
</head>
<body>

<?php
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
   </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> 
            
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>
Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

Hello...help me please

<?
$username="";
$password="";
$firstname="";
$lastname="";
$ydob="";
$mdob="";
$bdob="";
$email="";
$gender="";
$priority="";
$usid="";

$users= $_POST['txt_xml_users'];


$xml_Doc = new DOMDocument();
$xml_Doc->loadXML($users);


if(!$xml_Doc->schemaValidate('users.xsd'))
echo "Your xml is NOT valid";

else
{
include("dbconnect.php");
header('Content-Type: text/xml');
//$xml_users=simplexml_load_string($users );
$xml_users=simplexml_import_dom($xml_Doc);

foreach ($xml_users->user as $user)
{
$username=$user->username;
$password=$user->password;
$firstname=$user->firstname;
$lastname=$user->lastname;
$ydob=$user->ydob;
$mdob=$user->mdob;
$bdob=$user->bdob;
$email=$user->email;
$gender=$user->gender;
$priority=$user->priority;
$usid=$user->usid;

if($username!="" && $username!=null)
{
$sql_select="SELECT * FROM users WHERE

username='$username'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)

if($password!="" && $password!=null)
{
$sql_select="SELECT * FROM users WHERE

password='$password'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)

if($firstname!="" && $firstname!=null)
{
$sql_select="SELECT * FROM users WHERE

firstname='$firstname'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)

if($lastname!="" && $lastname!=null)
{
$sql_select="SELECT * FROM users WHERE

lastname='$lastname'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)


if($ydob!="" && $ydob!=null)
{
$sql_select="SELECT * FROM users WHERE ydob='$ydob'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)


if($mdob!="" && $mdob!=null)
{
$sql_select="SELECT * FROM users WHERE mdob='$mdob'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)


if($bdob!="" && $bdob!=null)
{
$sql_select="SELECT * FROM users WHERE bdob='$bdob'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)


if($email!="" && $email!=null)
{
$sql_select="SELECT * FROM users WHERE email='$email'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)


if($gender!="" && $gender!=null)
{
$sql_select="SELECT * FROM users WHERE gender='$gender'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)


if($priority!="" && $priority!=null)
{
$sql_select="SELECT * FROM users WHERE

priority='$priority'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)


if($usid!="" && $usid!=null)
{
$sql_select="SELECT * FROM users WHERE usid='$usid'";

$Rs = mysql_query($sql_select);

if (mysql_num_rows($Rs)<1)

//insert only if the data has not been inserted before
{
//we want to insert data

$sql_insert="INSERT INTO

modules(username,password,firstname,lastname,ydob,mdob,bdob,email,

gender,priority,usid)VALUES

('$username','$password','$firstname','$lastname','$ydob','$mdob',

'$bdob','$email','$gender','$priority','$usid')";

if (!mysql_query($sql_insert,$con))
{
die('Error: ' . mysql_error());
}
}//end if
}//end if
}//end if
}//end if
}//end if
}//end if
}//end if
}//end if
}//end if
}//end if
}//end if
}//end foreach
?>
<?
mysql_close($con);
}//end else
?>

am getting
Parse error: syntax error, unexpected $end in D:\xampp\htdocs\xampp\csite\process_reg.php on line 171

amee01
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Do not reply to old threads with a new problem, start a new thread. When you do, use code tags to highlight your source (and highlight the offending line).

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You