The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-DB - Error Executing PHP Code
Discuss Error Executing PHP Code in the PHP Development forum on Dev Shed. Error Executing PHP Code PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 4th, 2013, 06:17 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 15
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...
|

February 4th, 2013, 06:56 AM
|
|
|
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.
|

February 4th, 2013, 07:36 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 15
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. 
|

February 4th, 2013, 07:44 AM
|
|
|
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'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>
Last edited by gw1500se : February 4th, 2013 at 07:49 AM.
|

February 7th, 2013, 07:40 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 15
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

|

February 7th, 2013, 07:49 AM
|
|
|
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.
|

February 7th, 2013, 08:20 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 15
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 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|