[HELP] Please can some one point out a 'T_CONSTANT_ENCAPSED_STRING' error for me :)

Reply

Join Date: Sep 2009
Posts: 1
Reputation: iPixelate is an unknown quantity at this point 
Solved Threads: 0
iPixelate iPixelate is offline Offline
Newbie Poster

[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

  1. <h2>Add Rare</h2><br>
  2.  
  3. <?php
  4. $date = date("jS M Y");
  5. $time1 = date("h:ia");
  6. if (!$_POST[addincident]){
  7. ?>
  8.  
  9. <form method="post">
  10. <div class="greyBox"><strong>Date:</strong> <input name="date1" type="text" value="<?PHP echo $date ?>"></div>
  11. <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>
  12. <div class="greyBox"><strong>Name of Caller:</strong> <input name="caller" type="text"></div>
  13. <div class="greyBox"><strong>Caller Telephone Number:</strong> <input name="callerno" type="text" value"()"> <b>Example: (01635) 12345</b></div>
  14. <div class="greyBox"><strong>Caller Address:</strong> <textarea name="calleraddy" type="text"></textarea></div>
  15. <div class="greyBox"><strong>Service Required:</strong> <select name="service">
  16. <?php
  17. $getservice = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`");
  18. while ($service = mysql_fetch_array($getservice)){
  19. echo ("<option value=\"$service[id]\">$service[service]</option>
  20. ");}
  21. ?>
  22. </select>
  23. </div>
  24. <div class="greyBox"><strong> Secondary Service Required:</strong> <select name="service2">
  25. <?php
  26. $getservice2 = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`");
  27. while ($service2 = mysql_fetch_array($getservice2)){
  28. echo ("<option value=\"$service2[id]\">$service2[service]</option>
  29. ");}
  30. ?>
  31. <option value="Not Applicable">Not Applicable</option>
  32. </select>
  33. </div>
  34. <div class="greyBox"><strong>Location of Incident:</strong> <input name="location" type="text"></div>
  35. <div class="greyBox"><strong>Number of Person(s) Involved:</strong> <select name="persons">
  36. <option value="1">1</option>
  37. <option value="2">2</option>
  38. <option value="3">3</option>
  39. <option valu4="4">4</option>
  40. <option value="5">5</option>
  41. <option value="6">6</option>
  42. <option value="7">7</option>
  43. <option value="8">8</option>
  44. <option value="9">9</option>
  45. <option value="10">10</option>
  46. <option value="11">11</option>
  47. <option value="12">12</option>
  48. <option value="13">13</option>
  49. <option value="14">14</option>
  50. <option value="15">15</option>
  51. <option value="16">16</option>
  52. <option value="17">17</option>
  53. <option value="18">18</option>
  54. <option value="19">19</option>
  55. <option value="20">20</option>
  56. <option value="Other">Other (Please Specify)</option>
  57. </select> <input name="other" type="text"> Only fill in the box if the number of people involved exceeds 20. Otherwise, leave it blank!</div>
  58. <div class="greyBox"><strong>Incident Details:</strong> <textarea name="details"></textarea></div>
  59. <div class="greyBox"><strong>Call Handler:</strong> <?PHP echo $logged[username] ?></div>
  60. <input type="submit" name="addincident" value="Submit Incident Details">
  61.  
  62. <?php
  63. }else{
  64. $date1 = htmlspecialchars(addslashes($_POST[date1]));
  65. $time = htmlspecialchars(addslashes($_POST[time]));
  66. $caller = htmlspecialchars(addslashes($_POST[caller]));
  67. $callerno = htmlspecialchars(addslashes($_POST[callerno]));
  68. $calleraddy = htmlspecialchars(addslashes($_POST[calleraddy]));
  69. $service = htmlspecialchars(addslashes($_POST[service]));
  70. $service2 = htmlspecialchars(addslashes($_POST[service2]));
  71. $location = htmlspecialchars(addslashes($_POST[location]));
  72. $persons = htmlspecialchars(addslashes($_POST[persons]));
  73. $other = htmlspecialchars(addslashes($_POST[other]));
  74. $details = htmlspecialchars(addslashes($_POST[details]));
  75. if($date1==NULL || $time==NULL || $caller==NULL || $callerno==NULL || $calleraddy==NULL || $service==NULL || $service2==NULL || $location==NULL || $persons==NULL || $details==NULL || $service==$service2) {
  76. echo("<strong>You left some fields blank</strong><br>You will be redirected back to the open incident page.
  77. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">");
  78. }else{
  79. echo("<strong>Incident was successfully added</strong><br>You will be redirected back to the open incident page.
  80. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">");
  81. $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]."')";
  82. mysql_query($insertIncident) or die("MySQL Error.");
  83. $date = date("d/m/y - h:ia");
  84. $insertLog = "INSERT INTO `logs` ( `log` , `date` ) VALUES ('<strong>$logged[username]</strong> opened incident, location: <strong>$location</strong>', '$date')";
  85. mysql_query($insertLog) or die('MySQL Error.');
  86. }
  87. }
  88. ?>
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 62
Reputation: kylegetson is an unknown quantity at this point 
Solved Threads: 9
kylegetson's Avatar
kylegetson kylegetson is offline Offline
Junior Poster in Training

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:
  1. $string="Hello ".$name.", how are you?";

You can do:
  1. $string="Hello $name, how are you?";

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

here is your code corrected

  1. <h2>Add Rare</h2><br>
  2.  
  3. <?php
  4. $date = date("jS M Y");
  5. $time1 = date("h:ia");
  6. if (!$_POST[addincident]){
  7. ?>
  8.  
  9. <form method="post">
  10. <div class="greyBox"><strong>Date:</strong> <input name="date1" type="text" value="<?PHP echo $date ?>"></div>
  11. <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>
  12. <div class="greyBox"><strong>Name of Caller:</strong> <input name="caller" type="text"></div>
  13. <div class="greyBox"><strong>Caller Telephone Number:</strong> <input name="callerno" type="text" value"()"> <b>Example: (01635) 12345</b></div>
  14. <div class="greyBox"><strong>Caller Address:</strong> <textarea name="calleraddy" type="text"></textarea></div>
  15. <div class="greyBox"><strong>Service Required:</strong> <select name="service">
  16. <?php
  17. $getservice = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`");
  18. while ($service = mysql_fetch_array($getservice)){
  19. echo ("<option value=\"$service[id]\">$service[service]</option>
  20. ");}
  21. ?>
  22. </select>
  23. </div>
  24. <div class="greyBox"><strong> Secondary Service Required:</strong> <select name="service2">
  25. <?php
  26. $getservice2 = mysql_query("SELECT * FROM `services` ORDER BY `displayorder`");
  27. while ($service2 = mysql_fetch_array($getservice2)){
  28. echo ("<option value=\"$service2[id]\">$service2[service]</option>
  29. ");}
  30. ?>
  31. <option value="Not Applicable">Not Applicable</option>
  32. </select>
  33. </div>
  34. <div class="greyBox"><strong>Location of Incident:</strong> <input name="location" type="text"></div>
  35. <div class="greyBox"><strong>Number of Person(s) Involved:</strong> <select name="persons">
  36. <option value="1">1</option>
  37. <option value="2">2</option>
  38. <option value="3">3</option>
  39. <option valu4="4">4</option>
  40. <option value="5">5</option>
  41. <option value="6">6</option>
  42. <option value="7">7</option>
  43. <option value="8">8</option>
  44. <option value="9">9</option>
  45. <option value="10">10</option>
  46. <option value="11">11</option>
  47. <option value="12">12</option>
  48. <option value="13">13</option>
  49. <option value="14">14</option>
  50. <option value="15">15</option>
  51. <option value="16">16</option>
  52. <option value="17">17</option>
  53. <option value="18">18</option>
  54. <option value="19">19</option>
  55. <option value="20">20</option>
  56. <option value="Other">Other (Please Specify)</option>
  57. </select> <input name="other" type="text"> Only fill in the box if the number of people involved exceeds 20. Otherwise, leave it blank!</div>
  58. <div class="greyBox"><strong>Incident Details:</strong> <textarea name="details"></textarea></div>
  59. <div class="greyBox"><strong>Call Handler:</strong> <?PHP echo $logged[username] ?></div>
  60. <input type="submit" name="addincident" value="Submit Incident Details">
  61.  
  62. <?php
  63. }else{
  64. $date1 = htmlspecialchars(addslashes($_POST[date1]));
  65. $time = htmlspecialchars(addslashes($_POST[time]));
  66. $caller = htmlspecialchars(addslashes($_POST[caller]));
  67. $callerno = htmlspecialchars(addslashes($_POST[callerno]));
  68. $calleraddy = htmlspecialchars(addslashes($_POST[calleraddy]));
  69. $service = htmlspecialchars(addslashes($_POST[service]));
  70. $service2 = htmlspecialchars(addslashes($_POST[service2]));
  71. $location = htmlspecialchars(addslashes($_POST[location]));
  72. $persons = htmlspecialchars(addslashes($_POST[persons]));
  73. $other = htmlspecialchars(addslashes($_POST[other]));
  74. $details = htmlspecialchars(addslashes($_POST[details]));
  75. if($date1==NULL || $time==NULL || $caller==NULL || $callerno==NULL || $calleraddy==NULL || $service==NULL || $service2==NULL || $location==NULL || $persons==NULL || $details==NULL || $service==$service2) {
  76. echo("<strong>You left some fields blank</strong><br>You will be redirected back to the open incident page.
  77. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">");
  78. }else{
  79. echo("<strong>Incident was successfully added</strong><br>You will be redirected back to the open incident page.
  80. <meta http-equiv=\"Refresh\" content=\"3; URL=index.php?p=open_incident\">");
  81. $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]."')";
  82. mysql_query($insertIncident) or die("MySQL Error.");
  83. $date = date("d/m/y - h:ia");
  84. $insertLog = "INSERT INTO `logs` ( `log` , `date` ) VALUES ('<strong>$logged[username]</strong> opened incident, location: <strong>$location</strong>', '$date')";
  85. mysql_query($insertLog) or die('MySQL Error.');
  86. }
  87. }
  88. ?>
Last edited by kylegetson; Sep 17th, 2009 at 11:42 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: [HELP] Please can some one point out a 'T_CONSTANT_ENCAPSED_STRING' error for me

 
0
  #3
Sep 18th, 2009
Originally Posted by kylegetson View Post
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:
  1. $string="Hello ".$name.", how are you?";

You can do:
  1. $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,
  1. $string = "Hello ".$name['firstname'].", how you are?";

would become
  1. $string = "Hello ${name['firstname']}, how you are?";
or
  1. $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
  1. $string = "Hello " .$name['firstname']. ", how you are?";
The whitespace definitely helps readability, and might've helped the OP find his error sooner.
Last edited by Fest3er; Sep 18th, 2009 at 2:29 am.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC