0

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

<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.');
					}
					}
					?>
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Fest3er
0

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:

$string="Hello ".$name.", how are you?";

You can do:

$string="Hello $name, how are you?";

just be sure your using double quotes " and NOT single quotes '.

here is your code corrected

<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.');
					}
					}
					?>

Edited by kylegetson: n/a

0

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:

$string="Hello ".$name.", how are you?";

You can do:

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

$string = "Hello ".$name['firstname'].", how you are?";

would become

$string = "Hello ${name['firstname']}, how you are?";

or

$string = "Hello {$name['firstname']}, how you are?";

The braces are required to 'force' PHP to parse the string as desired. It only took me about five years to stop making this mistake.

Also, I prefer to write the original code as

$string = "Hello " .$name['firstname']. ", how you are?";

The whitespace definitely helps readability, and might've helped the OP find his error sooner.

Edited by Fest3er: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.