| | |
[HELP] Please can some one point out a 'T_CONSTANT_ENCAPSED_STRING' error for me :)
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2009
Posts: 1
Reputation:
Solved Threads: 0
[HELP] Please can some one point out a 'T_CONSTANT_ENCAPSED_STRING' error for me :)
0
#1 Sep 17th, 2009
Hey everyone 
I keep getting a 'T_CONSTANT_ENCAPSED_STRING' parse error on line 81 of this PHP script, however I can't find the issue. I am a little bit of a noob at PHP, I admit, but if someone could correct the issue for me that would be great!
This is for a system I am doing so that my College course, Uniformed Public Services can practise incident management like a 999 call operator
.
Thanks
Peter

I keep getting a 'T_CONSTANT_ENCAPSED_STRING' parse error on line 81 of this PHP script, however I can't find the issue. I am a little bit of a noob at PHP, I admit, but if someone could correct the issue for me that would be great!
This is for a system I am doing so that my College course, Uniformed Public Services can practise incident management like a 999 call operator
.Thanks

Peter
PHP Syntax (Toggle Plain Text)
<h2>Add Rare</h2><br> <?php $date = date("jS M Y"); $time1 = date("h:ia"); if (!$_POST[addincident]){ ?> <form method="post"> <div class="greyBox"><strong>Date:</strong> <input name="date1" type="text" value="<?PHP echo $date ?>"></div> <div class="greyBox"><strong>Time:</strong> <input name="time" type="text" value="<?PHP echo $time1 ?>"> <b>Example 1: 13:47</b> or <b>Example 2: 01:47 PM</b> </div> <div class="greyBox"><strong>Name of Caller:</strong> <input name="caller" type="text"></div> <div class="greyBox"><strong>Caller Telephone Number:</strong> <input name="callerno" type="text" value"()"> <b>Example: (01635) 12345</b></div> <div class="greyBox"><strong>Caller Address:</strong> <textarea name="calleraddy" type="text"></textarea></div> <div class="greyBox"><strong>Service Required:</strong> <select name="service"> <?php $getservice = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`"); while ($service = mysql_fetch_array($getservice)){ echo ("<option value=\"$service[id]\">$service[service]</option> ");} ?> </select> </div> <div class="greyBox"><strong> Secondary Service Required:</strong> <select name="service2"> <?php $getservice2 = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`"); while ($service2 = mysql_fetch_array($getservice2)){ echo ("<option value=\"$service2[id]\">$service2[service]</option> ");} ?> <option value="Not Applicable">Not Applicable</option> </select> </div> <div class="greyBox"><strong>Location of Incident:</strong> <input name="location" type="text"></div> <div class="greyBox"><strong>Number of Person(s) Involved:</strong> <select name="persons"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option valu4="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="Other">Other (Please Specify)</option> </select> <input name="other" type="text"> Only fill in the box if the number of people involved exceeds 20. Otherwise, leave it blank!</div> <div class="greyBox"><strong>Incident Details:</strong> <textarea name="details"></textarea></div> <div class="greyBox"><strong>Call Handler:</strong> <?PHP echo $logged[username] ?></div> <input type="submit" name="addincident" value="Submit Incident Details"> <?php }else{ $date1 = htmlspecialchars(addslashes($_POST[date1])); $time = htmlspecialchars(addslashes($_POST[time])); $caller = htmlspecialchars(addslashes($_POST[caller])); $callerno = htmlspecialchars(addslashes($_POST[callerno])); $calleraddy = htmlspecialchars(addslashes($_POST[calleraddy])); $service = htmlspecialchars(addslashes($_POST[service])); $service2 = htmlspecialchars(addslashes($_POST[service2])); $location = htmlspecialchars(addslashes($_POST[location])); $persons = htmlspecialchars(addslashes($_POST[persons])); $other = htmlspecialchars(addslashes($_POST[other])); $details = htmlspecialchars(addslashes($_POST[details])); if($date1==NULL || $time==NULL || $caller==NULL || $callerno==NULL || $calleraddy==NULL || $service==NULL || $service2==NULL || $location==NULL || $persons==NULL || $details==NULL || $service==$service2) { echo("<strong>You left some fields blank</strong><br>You will be redirected back to the open incident page. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">"); }else{ echo("<strong>Incident was successfully added</strong><br>You will be redirected back to the open incident page. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">"); $insertIncident = "INSERT INTO `incident` ( `date` , `time` , `caller` , `caller_address` , `location` , `contact_tel` , `service` , `service2` , `persons_involved` , `other` , `details` , `answered_by` ) VALUES ('".$date1."', '".$time."', '".$caller."', '".$calleraddy."', '".$location."', '".$callerno."', '".$service."', '".$service2."', '".$persons."', '".$other."', '".$details"', '".$logged[username]."')"; mysql_query($insertIncident) or die("MySQL Error."); $date = date("d/m/y - h:ia"); $insertLog = "INSERT INTO `logs` ( `log` , `date` ) VALUES ('<strong>$logged[username]</strong> opened incident, location: <strong>$location</strong>', '$date')"; mysql_query($insertLog) or die('MySQL Error.'); } } ?>
Re: [HELP] Please can some one point out a 'T_CONSTANT_ENCAPSED_STRING' error for me
0
#2 Sep 17th, 2009
Line 81, your missing a period. To avoid these kind of issues, you don't need to concatenate all that. You can put $data in a double quoted string. So instead of doing this:
You can do:
just be sure your using double quotes " and NOT single quotes '.
here is your code corrected
PHP Syntax (Toggle Plain Text)
$string="Hello ".$name.", how are you?";
You can do:
PHP Syntax (Toggle Plain Text)
$string="Hello $name, how are you?";
just be sure your using double quotes " and NOT single quotes '.
here is your code corrected
PHP Syntax (Toggle Plain Text)
<h2>Add Rare</h2><br> <?php $date = date("jS M Y"); $time1 = date("h:ia"); if (!$_POST[addincident]){ ?> <form method="post"> <div class="greyBox"><strong>Date:</strong> <input name="date1" type="text" value="<?PHP echo $date ?>"></div> <div class="greyBox"><strong>Time:</strong> <input name="time" type="text" value="<?PHP echo $time1 ?>"> <b>Example 1: 13:47</b> or <b>Example 2: 01:47 PM</b> </div> <div class="greyBox"><strong>Name of Caller:</strong> <input name="caller" type="text"></div> <div class="greyBox"><strong>Caller Telephone Number:</strong> <input name="callerno" type="text" value"()"> <b>Example: (01635) 12345</b></div> <div class="greyBox"><strong>Caller Address:</strong> <textarea name="calleraddy" type="text"></textarea></div> <div class="greyBox"><strong>Service Required:</strong> <select name="service"> <?php $getservice = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`"); while ($service = mysql_fetch_array($getservice)){ echo ("<option value=\"$service[id]\">$service[service]</option> ");} ?> </select> </div> <div class="greyBox"><strong> Secondary Service Required:</strong> <select name="service2"> <?php $getservice2 = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`"); while ($service2 = mysql_fetch_array($getservice2)){ echo ("<option value=\"$service2[id]\">$service2[service]</option> ");} ?> <option value="Not Applicable">Not Applicable</option> </select> </div> <div class="greyBox"><strong>Location of Incident:</strong> <input name="location" type="text"></div> <div class="greyBox"><strong>Number of Person(s) Involved:</strong> <select name="persons"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option valu4="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="Other">Other (Please Specify)</option> </select> <input name="other" type="text"> Only fill in the box if the number of people involved exceeds 20. Otherwise, leave it blank!</div> <div class="greyBox"><strong>Incident Details:</strong> <textarea name="details"></textarea></div> <div class="greyBox"><strong>Call Handler:</strong> <?PHP echo $logged[username] ?></div> <input type="submit" name="addincident" value="Submit Incident Details"> <?php }else{ $date1 = htmlspecialchars(addslashes($_POST[date1])); $time = htmlspecialchars(addslashes($_POST[time])); $caller = htmlspecialchars(addslashes($_POST[caller])); $callerno = htmlspecialchars(addslashes($_POST[callerno])); $calleraddy = htmlspecialchars(addslashes($_POST[calleraddy])); $service = htmlspecialchars(addslashes($_POST[service])); $service2 = htmlspecialchars(addslashes($_POST[service2])); $location = htmlspecialchars(addslashes($_POST[location])); $persons = htmlspecialchars(addslashes($_POST[persons])); $other = htmlspecialchars(addslashes($_POST[other])); $details = htmlspecialchars(addslashes($_POST[details])); if($date1==NULL || $time==NULL || $caller==NULL || $callerno==NULL || $calleraddy==NULL || $service==NULL || $service2==NULL || $location==NULL || $persons==NULL || $details==NULL || $service==$service2) { echo("<strong>You left some fields blank</strong><br>You will be redirected back to the open incident page. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">"); }else{ echo("<strong>Incident was successfully added</strong><br>You will be redirected back to the open incident page. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">"); $insertIncident = "INSERT INTO `incident` ( `date` , `time` , `caller` , `caller_address` , `location` , `contact_tel` , `service` , `service2` , `persons_involved` , `other` , `details` , `answered_by` ) VALUES ('".$date1."', '".$time."', '".$caller."', '".$calleraddy."', '".$location."', '".$callerno."', '".$service."', '".$service2."', '".$persons."', '".$other."', '".$details."', '".$logged[username]."')"; mysql_query($insertIncident) or die("MySQL Error."); $date = date("d/m/y - h:ia"); $insertLog = "INSERT INTO `logs` ( `log` , `date` ) VALUES ('<strong>$logged[username]</strong> opened incident, location: <strong>$location</strong>', '$date')"; mysql_query($insertLog) or die('MySQL Error.'); } } ?>
Last edited by kylegetson; Sep 17th, 2009 at 11:42 pm.
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
Re: [HELP] Please can some one point out a 'T_CONSTANT_ENCAPSED_STRING' error for me
0
#3 Sep 18th, 2009
•
•
•
•
Line 81, your missing a period. To avoid these kind of issues, you don't need to concatenate all that. You can put $data in a double quoted string. So instead of doing this:
PHP Syntax (Toggle Plain Text)
$string="Hello ".$name.", how are you?";
You can do:
PHP Syntax (Toggle Plain Text)
$string="Hello $name, how are you?";
just be sure your using double quotes " and NOT single quotes '.
KG,
Your advice is sound, except when referencing array elements. That is,
PHP Syntax (Toggle Plain Text)
$string = "Hello ".$name['firstname'].", how you are?";
would become
PHP Syntax (Toggle Plain Text)
$string = "Hello ${name['firstname']}, how you are?";
PHP Syntax (Toggle Plain Text)
$string = "Hello {$name['firstname']}, how you are?";
Also, I prefer to write the original code as
PHP Syntax (Toggle Plain Text)
$string = "Hello " .$name['firstname']. ", how you are?";
Last edited by Fest3er; Sep 18th, 2009 at 2:29 am.
![]() |
Similar Threads
- help with strange error (Python)
- DLL Global Object Constructor String Error (C++)
- OnCalcField modifying its own DataSet - Error (Pascal and Delphi)
- VB6 - Look up email address from outlook address book? (Visual Basic 4 / 5 / 6)
- Help with: Unqualified exec error (Python)
- MIPS - convert integer to floating point?? (Assembly)
- floating point : overflow error (C)
Other Threads in the PHP Forum
- Previous Thread: PHP code to send email
- Next Thread: Joomla left panel problem
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





