Page 1 of 1

I cannot find error, please help

Posted: Tue Apr 25, 2006 9:36 pm
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 />";

      }

}

?>

Posted: Tue Apr 25, 2006 9:52 pm
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.

Try this

Posted: Wed Apr 26, 2006 1:37 am
by dibyendrah
might be $HTTP_POST_VARS['subject'] works instead of $_POST[subject]. Just a guess. I din't get any parse error.