PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 4th, 2013, 06:17 AM
gahuja91 gahuja91 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 15 gahuja91 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 33 sec
Reputation Power: 0
PHP-DB - 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'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" 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...

Reply With Quote
  #2  
Old February 4th, 2013, 06:56 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
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.

Reply With Quote
  #3  
Old February 4th, 2013, 07:36 AM
gahuja91 gahuja91 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 15 gahuja91 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 33 sec
Reputation Power: 0
I've removed the quote you mentioned. Still is is showing the same error.

Reply With Quote
  #4  
Old February 4th, 2013, 07:44 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
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.

Reply With Quote
  #5  
Old February 7th, 2013, 07:40 AM
gahuja91 gahuja91 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 15 gahuja91 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 33 sec
Reputation 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


Reply With Quote
  #6  
Old February 7th, 2013, 07:49 AM
Aurum84 Aurum84 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 74 Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 23 h 5 m 49 sec
Reputation Power: 17
Quote:
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.

Reply With Quote
  #7  
Old February 7th, 2013, 08:20 AM
gahuja91 gahuja91 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 15 gahuja91 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 33 sec
Reputation 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-DB - Error Executing PHP Code

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap