#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    15
    Rep Power
    0

    Error Executing PHP Code


    Hi everyone,
    I am trying to execute a php file I wrote but this error keeps coming up:
    Parse error: syntax error, unexpected 's' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\PHP\Chapter3\sendmail.php on line 43
    Here's my code:
    PHP Code:
    <html>
    <head>
      <title>Make Me Elvis - Send Email</title>
      <link rel="stylesheet" type="text/css" href = "sendstyle.css"/>
    </head>
    <body>
      <img src = "elvislogo.gif"/>
      <p>PRIVATE: For Elmer's use ONLY...</p>
      <p>Write and send an email to mailing list members</p>
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <label for="subject">Subject Of Email</label>
        <input name="subject" id="subject" type="text"/><br/>
        <label for = "body">Body Of Email</label>
        <textarea name="body" id="body" rows="8" cols="60"></textarea><br/>
        <input name="send" id="send" type="submit" value="Send Email"/>
      </form>

      <?php
         $output_form 
    false;
         if(isset(
    $_POST['send']))
         {
            
    $from 'abc@gmail.com';
            
    $subject $_POST['subject'];
            
    $body $_POST['body'];     

            if(empty(
    $subject) && empty($body))
            {
        echo 
    '************************************<br/>';
        echo 
    'You forgot the email subject and body text<br/>';
        echo 
    '************************************<br/><br/><br/>';
         
    $output_form true;
            }
            if(empty(
    $subject) && (!empty($body)))
            {
        echo 
    '*****************************<br/>';
        echo 
    'You forgot the email subject<br/>';
        echo 
    '*****************************<br/><br/><br/>';
         
    $output_form true;
            }
            if((!empty(
    $subject)) && empty($body))
            {
        echo 
    '****************************<br/>';
        echo 
    'You forgot the email's body text<br/>';
        echo '
    ****************************<br/><br/><br/>';
         $output_form = true;
            }
            if((!empty($subject)) && (!empty($body)))
            {
        $db = mysqli_connect('
    localhost', 'root', '', 'elvis_store')
        or die('
    Error connecting to database');

        $query = "SELECT * FROM email_list";

        $result = mysqli_query($db, $query)
        or die('
    Error queryig database');

        while($row = mysqli_fetch_array($result))
        {
            $to = $row['
    email'];
            $fname = $row['
    fname'];
            $lname = $row['
    lname'];
            $msg = "Dear $fname $lname, \n$body";
            mail($to, $subject, $msg, '
    From:' . $from);
            echo '
    Email sent to ' . $fname $lname . '<' . $to . '><br/>'; 
        }
            }
         }
         if($output_form)
         {
      ?>
      <img src = "elvislogo.gif"/>
      <p>PRIVATE: For Elmer'
    use ONLY...</p>
      <
    p>Write and send an email to mailing list members</p>
      <
    form method "post" action "<?php echo $_SERVER['PHP_SELF']; ?>">
        <
    label for="subject">Subject Of Email</label>
        <
    input name="subject" id="subject" type="text" value "<?php echo $subject; ?

    >"
    /><br/>
        <
    label for = "body">Body Of Email</label>
        <
    textarea name="body" id="body" rows="8" cols="60"><?php echo $body; ?

    ></
    textarea><br/>
        <
    input name="send" id="send" type="submit" value="Send Email"/>
      </
    form>
     
     <?
    php
         
    }
      
    ?>

    </body>
    </html>
    I've tried to locate the error but cannot find any. Please see to it and lemme know any changes rqrd.
    Thanks...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    As you can see from the formatting, your quotes are messed up. You need to escape that single quote (apostrophe).
    Code:
    <p>PRIVATE: For Elmer\'s use ONLY...</p>
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    15
    Rep Power
    0
    I've removed the quote you mentioned. Still is is showing the same error.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    I think I see the problem. Try it this way (note the leading <?php ?> tags are just for the formatter).
    PHP Code:
    <?php ?>
     <html>
    <head>
      <title>Make Me Elvis - Send Email</title>
      <link rel="stylesheet" type="text/css" href = "sendstyle.css"/>
    </head>
    <body>
      <img src = "elvislogo.gif"/>
      <?php echo "<p>PRIVATE: For Elmer\'s use ONLY...</p>
      <p>Write and send an email to mailing list members</p>
      <form method=\"post\" action=\""
    .$_SERVER['PHP_SELF']."\">";?>
        <label for="subject">Subject Of Email</label>
        <input name="subject" id="subject" type="text"/><br/>
        <label for = "body">Body Of Email</label>
        <textarea name="body" id="body" rows="8" cols="60"></textarea><br/>
        <input name="send" id="send" type="submit" value="Send Email"/>
      </form>

      <?php
         $output_form 
    false;
         if(isset(
    $_POST['send']))
         {
            
    $from 'abc@gmail.com';
            
    $subject $_POST['subject'];
            
    $body $_POST['body'];     

            if(empty(
    $subject) && empty($body))
            {
        echo 
    '************************************<br/>';
        echo 
    'You forgot the email subject and body text<br/>';
        echo 
    '************************************<br/><br/><br/>';
         
    $output_form true;
            }
            if(empty(
    $subject) && (!empty($body)))
            {
        echo 
    '*****************************<br/>';
        echo 
    'You forgot the email subject<br/>';
        echo 
    '*****************************<br/><br/><br/>';
         
    $output_form true;
            }
            if((!empty(
    $subject)) && empty($body))
            {
        echo 
    '****************************<br/>';
        echo 
    'You forgot the email's body text<br/>';
        echo '
    ****************************<br/><br/><br/>';
         $output_form = true;
            }
            if((!empty($subject)) && (!empty($body)))
            {
        $db = mysqli_connect('
    localhost', 'root', '', 'elvis_store')
        or die('
    Error connecting to database');

        $query = "SELECT * FROM email_list";

        $result = mysqli_query($db, $query)
        or die('
    Error queryig database');

        while($row = mysqli_fetch_array($result))
        {
            $to = $row['
    email'];
            $fname = $row['
    fname'];
            $lname = $row['
    lname'];
            $msg = "Dear $fname $lname, \n$body";
            mail($to, $subject, $msg, '
    From:' . $from);
            echo '
    Email sent to ' . $fname $lname . '<' . $to . '><br/>'; 
        }
            }
         }
         if($output_form)
         {
      ?>
      <img src = "elvislogo.gif"/>
      <p>PRIVATE: For Elmer'
    use ONLY...</p>
      <
    p>Write and send an email to mailing list members</p>
      <
    form method "post" action "<?php echo $_SERVER['PHP_SELF']; ?>">
        <
    label for="subject">Subject Of Email</label>
        <
    input name="subject" id="subject" type="text" value "<?php echo $subject; ?

    >"
    /><br/>
        <
    label for = "body">Body Of Email</label>
        <
    textarea name="body" id="body" rows="8" cols="60"><?php echo $body; ?

    ></
    textarea><br/>
        <
    input name="send" id="send" type="submit" value="Send Email"/>
      </
    form>
     
     <?
    php
         
    }
      
    ?>

    </body>
    </html>
    Last edited by gw1500se; February 4th, 2013 at 07:49 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    15
    Rep Power
    0
    It's still not running. The code posted by you is showing the following error:
    Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\PHP\Chapter3\sendmail2.php on line 11

  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    18
    Originally Posted by gahuja91
    It's still not running. The code posted by you is showing the following error:
    Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\PHP\Chapter3\sendmail2.php on line 11

    I ran the code and I don't encounter that parse error.
    Instead there are 3 syntax errors, the first is on the line:


    echo 'You forgot the email's body text<br/>';

    note the ' in email's,

    After that there are 2 instances of a miswritten php end tag: ? >


    EDIT: that aside, may I advice you to use the attribute 'required' in an input tag? that saves you writing validation code to check if a value was put in
    Last edited by Aurum84; February 7th, 2013 at 07:58 AM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    15
    Rep Power
    0
    Thanks Aurum84
    You made my day. This PHP file of mine was lying around as a waste.
    You found the error...
    Thanks again

IMN logo majestic logo threadwatch logo seochat tools logo