I cannot find error, please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

I cannot find error, please help

Post by bruceg »

I cannot find the error I am getting with this code whch is:

Parse error: syntax error, unexpected '}' in /hsphere/local/home/bruceg/inspired-evolution.com/do_send_newsletter.php on line 23

please assist, here is code

Code: Select all

<?php

// check for required fields

if (($_POST[subject] ==" ") || ($_POST[newsletter] =="") ) {

      header("Location: http://www.inspired-evolution.com");

      exit;

} else {

//set up table and database names

$db_name ="bruceg_mailinglist" ;

$table_name = "subscribers" ;

//connect to server and select DB

$connection = @mysql_connect("localhost", "username", "password" )

or die(mysql_error());

$db = @mysql_select_db($db_name, $connection) or die (mysql_error());

//build and issue query

$sql = "select email_addr from $table_name" ;

$result = @mysql_query($sql, $connection) or die(mysql_error());

//create a From: mailheaders

$headers = "From: Inspired-Evolution.com <webguync@gmail.com>\n";

//loop through results and send mail

while ($row = mysql_fetch_array($result)) {

$email_addr = $row[ 'email_addr' ];

mail ("$email_addr", stripslashes($_POST[subject] ),

         stripslashes($_POST[newsletter] ), $headers);

       echo "newsletter has been sent to: $email_addr<br />";

      }

}

?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

There is no parse error in that code.

You might want to avoid notices by changing

Code: Select all

$_POST[newsletter]
to

Code: Select all

$_POST['newsletter']
.

It is best practice to always code with atleast

Code: Select all

error_reporting(E_ALL);
set to avoid uninitialized variables.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Try this

Post by dibyendrah »

might be $HTTP_POST_VARS['subject'] works instead of $_POST[subject]. Just a guess. I din't get any parse error.
Post Reply