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>

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.

:) 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)){session_register('captcha');}

Replace this line by this.

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

Cheers,
Naveen

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

ORIGINAL

<?php
session_start();


if(!isset($_SESSION)){session_register('captcha');}
$PHP_SELF = $_SERVER;
$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)){session_register('captcha');}
$PHP_SELF = $_SERVER;
$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;
}
}

Edited 3 Years Ago by happygeek: fixed formatting

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 error

Parse error: syntax error, unexpected T_ELSE

:)

Edited 3 Years Ago by happygeek: fixed formatting

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

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.

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

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>

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

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.

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.

Comments
you can use as many
Wrong comment, in 3years old thread.
why bother necroposting?

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

Edited 5 Years Ago by ko ko: Wrong grammar

Hello...help me please

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


$users= $_POST;



$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

Edited 3 Years Ago by Nick Evan: Fixed formatting

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).

It took me quite a while to figure this one out myself. I use Xampp for my testing locally (so I don't crash my shared server), then I upload it to the remote system for production.. Get this, your only problem was probably the following line.

// lettera

I don't know why, but not all PHP processors will accept this as a comment. For some reason, it seems to comment the entire rest of the file.

Consider using the other method of commenting
/* lettera */

There was absolutely no reference to this issue when I looked through for a few hours. I eventually chopped my code down by pieces until I figured this one out. Good god.

Hope this helps you and others trying to figure out what the heck is wrong..

Also, you might consider using <? instead of <?php and set your php.ini file to include
short_open_tag=1

This article has been dead for over six months. Start a new discussion instead.