473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

unexpected T_IF error

4
I am trying to use a script to send a list of items from a database. The code is listed below. I get an unexpected T_IF error on the second $mailer->Body line (line 55). If I comment out the 9 $mailer->Body lines with php code (55-62 and 64), the script works correctly.

I am relatively new to coding, so I am sure I have left something out, I just do not know what. Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. ?php require_once('Connections/jma.php'); ?>
  2. <?php require_once("Connections/dbConnection.php"); ?>
  3. <?php
  4. $date = date('Y-m-d');
  5. $days_to_add = 7;
  6. $dateArray = explode("-",$date);
  7. $startTimestamp = mktime(0,0,0,$dateArray[1],$dateArray[2],$dateArray[0]);
  8. $endTimestamp = mktime(23,59,0,$dateArray[1],$dateArray[2]+$days_to_add,$dateArray[0]);
  9. // Create SQL to read in database records
  10. $sql  = "SELECT id,title,body, UNIX_TIMESTAMP(dateField) AS timestampField  ";
  11. $sql .= "FROM calendardata ";
  12. $sql .= "WHERE UNIX_TIMESTAMP(dateField) >= " . $startTimestamp . " AND UNIX_TIMESTAMP(dateField) <= " . $endTimestamp . " ";
  13. $sql .= "ORDER BY UNIX_TIMESTAMP(dateField) ASC";
  14.  
  15. // Open Database Connection    
  16. $dbLink = mysql_connect($dbHost, $dbUser, $dbPass);
  17. if (!$dbLink){
  18.   die ("Database: Couldn`t connect to mySQL Server");
  19. }
  20. mysql_select_db($dbName, $dbLink) 
  21.   or die ("Database: Couldn`t open Database"); 
  22.  
  23. // Read in Records from Database  
  24. $dbResult = mysql_query($sql, $dbLink)
  25.   or die ("MySQL Error: " . mysql_error() );
  26. $numRecords = mysql_num_rows($dbResult);
  27. for($i=0;$i < $numRecords;$i++){
  28.     $temp = mysql_fetch_assoc($dbResult);
  29.     if (!get_magic_quotes_gpc()) {
  30.         $temp['title'] = stripslashes($temp['title']);
  31.         $temp['body'] = stripslashes($temp['body']);
  32.     }
  33.     $records[] = $temp;
  34. }
  35.  
  36. // Close Database Connection  
  37. mysql_close($dbLink);
  38. ?>
  39. <?php 
  40.  
  41. // Grab our config settings 
  42. require_once($_SERVER['DOCUMENT_ROOT'].'/config.php'); 
  43.  
  44. // Grab the FreakMailer class 
  45. require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc'); 
  46.  
  47. // instantiate the class 
  48. $mailer = new FreakMailer(); 
  49.  
  50. // Set the subject 
  51. $mailer->Subject = 'This is a test'; 
  52.  
  53. // Body 
  54. $mailer->Body = '<p>This is a list of all events (field trips, guest speakers, assemblies, etc) occurring at John Milledge in the next seven days. Any events that will affect the normal school day should be listed here. If you know of an event that should be listed, please email the event to <a href=\"mailto:lstephens@johnmilledge.org\">Linda Stephens</a>. Please keep in mind that all of these events do not appear on the John Milledge website.</p><p><br> ';
  55. $mailer->Body .=  if ($numRecords <> 0) { ;
  56. $mailer->Body .= foreach($records as $record);
  57. $mailer->Body .= { $time=date("h:i a", $record['timestampField']) ;
  58. $mailer->Body .= if ($time=="12:00 pm"){ echo date("l m-d", $record['timestampField'])} ;
  59. $mailer->Body .= else {echo date("l m-d h:i a", $record['timestampField'])} echo $record['title'] ;
  60. $mailer->Body .= if($record['title']==$record['body']) {""};
  61. $mailer->Body .= else { echo $record['body']} . '</p><hr> ' .  } } ;
  62. $mailer->Body .= if ($numRecords == 0) {  ;
  63. $mailer->Body .= '</p> There are no events planned in the next seven days.';
  64. $mailer->Body .=  }; 
  65. $mailer->isHTML(true); 
  66.  
  67. // Add an address to send to. 
  68. $mailer->AddAddress('keley@johnmilledge.org', 'Kendall Eley'); 
  69.  
  70. if(!$mailer->Send()) 
  71.   echo 'There was a problem sending this mail!'; 
  72. else 
  73.   echo 'Mail sent!'; 
  74. $mailer->ClearAddresses(); 
  75. $mailer->ClearAttachments(); 
  76. ?> 
  77.  
Jul 25 '07 #1
7 1379
mwasif
802 Expert 512MB
What do you want to do in the following code (line 55 to 64)? The problem lies in these line

[PHP]$mailer->Body .= if ($numRecords <> 0) { ;
$mailer->Body .= foreach($records as $record);
$mailer->Body .= { $time=date("h:i a", $record['timestampField']) ;
$mailer->Body .= if ($time=="12:00 pm"){ echo date("l m-d", $record['timestampField'])} ;
$mailer->Body .= else {echo date("l m-d h:i a", $record['timestampField'])} echo $record['title'] ;
$mailer->Body .= if($record['title']==$record['body']) {""};
$mailer->Body .= else { echo $record['body']} . '</p><hr> ' . } } ;
$mailer->Body .= if ($numRecords == 0) { ;
$mailer->Body .= '</p> There are no events planned in the next seven days.';
$mailer->Body .= }; [/PHP]

Take a look at this to learn how to concatenate string in PHP.
Jul 25 '07 #2
keley
4
What do you want to do in the following code (line 55 to 64)? The problem lies in these line

[PHP]$mailer->Body .= if ($numRecords <> 0) { ;
$mailer->Body .= foreach($records as $record);
$mailer->Body .= { $time=date("h:i a", $record['timestampField']) ;
$mailer->Body .= if ($time=="12:00 pm"){ echo date("l m-d", $record['timestampField'])} ;
$mailer->Body .= else {echo date("l m-d h:i a", $record['timestampField'])} echo $record['title'] ;
$mailer->Body .= if($record['title']==$record['body']) {""};
$mailer->Body .= else { echo $record['body']} . '</p><hr> ' . } } ;
$mailer->Body .= if ($numRecords == 0) { ;
$mailer->Body .= '</p> There are no events planned in the next seven days.';
$mailer->Body .= }; [/PHP]

Take a look at this to learn how to concatenate string in PHP.
The code I list below is where I got the idea for the code above. The code below outputs a list of dates and events to a webpage. If there are no events, the code outputs There are no events planned in the next seven days.

What I want is to email this list daily to a specific email address. I thought that this script would be the best way to do that.

Expand|Select|Wrap|Line Numbers
  1. <?php if ($numRecords <> 0) { // Show if recordset not empty ?>
  2. <?php foreach($records as $record){ ?>
  3.           <?php $time=date("h:i a", $record['timestampField']); 
  4.                               if ($time=="12:00 pm"){ echo date("l m-d", $record['timestampField']);} else {echo date("l m-d h:i a", $record['timestampField']);}?>
  5. &nbsp;          <?php echo $record['title']; ?>
  6.           <?php if($record['title']==$record['body']) {"";}else { echo $record['body'];} ?>
  7.  </p>
  8.  <hr>
  9.         <?php } ?>
  10. <?php } // Show if recordset not empty ?>
  11.         <?php if ($numRecords == 0) { // Show if recordset empty ?>
  12. </p>
  13. There are no events planned in the next seven days.
  14. <?php } // Show if recordset empty ?>
Jul 25 '07 #3
mwasif
802 Expert 512MB
In your code, you are trying to display and email the content at the same time. First assign the content to a variable and then use that variable to email and display the message.

Did you read my provided link?
Jul 25 '07 #4
keley
4
In your code, you are trying to display and email the content at the same time. First assign the content to a variable and then use that variable to email and display the message.

Did you read my provided link?
I read the link and I have amended the code as follows but I get the same result. What am I missing? I am sure it is obvious, I am just not smart enough to see it.

Expand|Select|Wrap|Line Numbers
  1. $content = ' <p>This is a list of all events (field trips, guest speakers, assemblies, etc) occurring at John Milledge in the next seven days. Any events that will affect    the normal school day should be listed here. If you know of an event that should be listed, please email the event to <a href=\"mailto:lstephens@johnmilledge.org\">Linda Stephens</a>. Please keep in mind that all of these events do not appear on the John Milledge website.</p>  <p><br> ' ;
  2. $content .=  if ($numRecords <> 0) { ;
  3. $content .= foreach($records as $record);
  4. $content .= { $time=date("h:i a", $record['timestampField']) ;
  5. $content .= if ($time=="12:00 pm"){ echo date("l m-d", $record['timestampField'])} ;
  6. $content .= else {echo date("l m-d h:i a", $record['timestampField'])} echo $record['title'] ;
  7. $content .= if($record['title']==$record['body']) {""};
  8. $content .= else { echo $record['body']} . '</p><hr> ' .  } } ;
  9. $content .= if ($numRecords == 0) {  ;
  10. $content .= '</p> There are no events planned in the next seven days.';
  11. $content .=  };
  12.  
  13. $mailer->Body = $content;
  14.  
Jul 25 '07 #5
mwasif
802 Expert 512MB
The syntax will be something like

[PHP]$content = ' <p>This is a list of all events (field trips, guest speakers, assemblies, etc) occurring at John Milledge in the next seven days. Any events that will affect the normal school day should be listed here. If you know of an event that should be listed, please email the event to <a href=\"mailto:lstephens@johnmilledge.org\">Linda Stephens</a>. Please keep in mind that all of these events do not appear on the John Milledge website.</p> <p><br> ' ;
if($numRecords <> 0)
{
foreach($records as $record)
{
$time=date("h:i a", $record['timestampField']) ;
if ($time=="12:00 pm")
{
$content.= date("l m-d", $record['timestampField']);
// rest of the code
}
// some code here
}
}[/PHP]
This is invalid code
[PHP]$mailer->Body .= if ($numRecords <> 0) { ;
$mailer->Body .= foreach($records as $record);[/PHP]
This is how if else works
Jul 25 '07 #6
keley
4
Thanks. I am slow, but I finally realized what you are talking about. I have it working fine. Thanks for the help.
Jul 25 '07 #7
mwasif
802 Expert 512MB
Thanks. I am slow, but I finally realized what you are talking about. I have it working fine. Thanks for the help.
No problem, post back whenever you need help!
Jul 25 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: James Campbell | last post by:
ok, I am totally new to php and come from an asp background. I basically want to do an If > then > else > end if statement: my page is: <?php require_once('Connections/carresa.php'); ?>...
3
by: Eric Anderson Vianet SAO | last post by:
hello all When i tried ´pg_dump -v -f dump.dmp dtbtransporte´ I got the error: pg_dump: restoring data for table tbdmovimento pg_dump: dumping out the contents of table tbdmovimento ...
5
by: Vijayakrishna Pondala | last post by:
Hi, We are using the following error randomly, when accessing a webservice method/servlet hosted on JBoss application server: The underlying connection was closed: An unexpected error occurred...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
8
by: Jim Michaels | last post by:
C:\prj\quiz\withusers>php tareports.php PHP Parse error: syntax error, unexpected T_ELSE in C:\prj\quiz\withusers\tareports.php on line 205 this is the section of code. if (isset($row4)) {...
11
by: MLH | last post by:
Private Sub ButtonP_Click() On Error GoTo Err_ButtonP_Click Dim ThisForm As String ThisForm = Me.Name Exit_ButtonP_Click: Exit Sub Err_ButtonP_Click: Dim r As String, k As String, Message3...
8
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine...
5
praclarush
by: praclarush | last post by:
I've just started php, and this is a class assignment, but my question is I’m getting this error PHP Parse error: syntax error, unexpected T_IF, expecting T_VARIABLE or '$' in...
6
by: Ciaroscuro | last post by:
Howdy - In setting up a registration form, I'd like to keep any correct entries on the form (make them sticky). The Registration Form is "included" and has the the following structure: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.