bravo14 Posted July 4, 2009 Share Posted July 4, 2009 Hi Guys I have the following error Parse error: syntax error, unexpected T_ELSE in /home/sites/maypolejuniors.com/public_html/subscribe.php on line 168 from the following code <?php include_once('includes/connect.php'); //assign form entries from subscription form to variables $email=$_POST["form_email"]; $name=$_POST["form_name"]; $status=$_POST["form_subscribe2"]; echo ("status ".$status); if($status=="1"){ $result="$sql = 'SELECT * FROM `email_table` where `email`=$email"; if(mysql_num_rows($result) > 0) { echo('The email address '.$email.' is already subscribed to the Maypole Juniors newsletter'); } else { $sql="INSERT INTO `email_table` (`name`,`email`) VALUES ('".$name."', '".$email."')"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } else { echo($name. ' who has '.$email.' as their email address has successfully subscribed to the Maypole Juniors newsletter'); } } else //line 168 { echo("Do something else"); $sql="DELETE FROM email_table WHERE email='".$email."'"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } else { echo($name. ' who has '.$email.' as their email address has successfully unsubscribed from the Maypole Juniors newsletter'); } } } mysql_close($con); ?> Any ideas what I have wrong? Quote Link to comment Share on other sites More sharing options...
Dathremar Posted July 4, 2009 Share Posted July 4, 2009 if($status=="1"){ $result="$sql = 'SELECT * FROM `email_table` where `email`=$email"; if(mysql_num_rows($result) > 0) { echo('The email address '.$email.' is already subscribed to the Maypole Juniors newsletter'); } } // missing bracket else { You are missing a bracket Quote Link to comment Share on other sites More sharing options...
bravo14 Posted July 5, 2009 Author Share Posted July 5, 2009 Thanls for that, I now have the same on line 171 <?php include_once('includes/connect.php'); //assign form entries from subscription form to variables $email=$_POST["form_email"]; $name=$_POST["form_name"]; $status=$_POST["form_subscribe2"]; echo ("status ".$status); if($status=="1"){ $result="$sql = 'SELECT * FROM `email_table` where `email`=$email"; //is the email address already subsribed if(mysql_num_rows($result) > 0) { //The email address already exists in the table, output message echo('The email address '.$email.' is already subscribed to the Maypole Juniors newsletter'); } } else //if not then enter into database { $sql="INSERT INTO `email_table` (`name`,`email`) VALUES ('".$name."', '".$email."')"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } else { echo($name. ' who has '.$email.' as their email address has successfully subscribed to the Maypole Juniors newsletter'); } } else //line 171 { echo("Do something else"); $sql="DELETE FROM email_table WHERE email='".$email."'"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } else { echo($name. ' who has '.$email.' as their email address has successfully unsubscribed from the Maypole Juniors newsletter'); } } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 5, 2009 Share Posted July 5, 2009 If you indented your code more consistently you would likely see the errors yourself. Quote Link to comment Share on other sites More sharing options...
haku Posted July 5, 2009 Share Posted July 5, 2009 Exactly. Try this (its what I use, though it's not the standard): if(something) { if(something else) { // do whatever } else { // whatever } } else { if(another thing) { // do whatever } else { //do whatever } } See how easy that is to read? And if there is a brace missing, you can figure out where it is very fast. You can also figure out where the problem is when if/else statements are acting unexpectedly. Quote Link to comment Share on other sites More sharing options...
bravo14 Posted July 5, 2009 Author Share Posted July 5, 2009 Cheers Guys I have got the T Else to disappear and the Insert query works but I get the following errors displayed Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sites/maypolejuniors.com/public_html/subscribe2.php on line 153 Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/sites/maypolejuniors.com/public_html/subscribe2.php on line 158 The code now lookds like this include_once ('includes/connect.php'); //assign form entries from subscription form to variables $email = $_POST["form_email"]; $name = $_POST["form_name"]; $status = $_POST["form_subscribe2"]; echo ("status " . $status); $result="$sql='SELECT *FROM `email_table` where `email`=$email"; if(mysql_num_rows($result)>0) { echo('The email address '.$email.' is already subscribed to the Maypole Juniors newsletter'); } else if(mysql_numrows($result)==0) { $sql="INSERT INTO `email_table` (`name`,`email`) VALUES ('".$name."','".$email."')"; if(!mysql_query($sql,$con)) { die('Error: '.mysql_error()); } else { echo($name.' who has '.$email.' as their email address has successfully subscribed to the Mayple Juniors newsletter'); } } else { $sql="DELETE FROM `email_table` WHERE email='".$email."'"; if(!mysql_query($sql,$con)) { die('Error: '.mysql_error()); } else { echo($name.' who has '.$email.' as their email address has successfully unsubscribed from the Maypole Juniors newsletter'); } } ?> Quote Link to comment Share on other sites More sharing options...
haku Posted July 5, 2009 Share Posted July 5, 2009 For a new topic, you are best off starting a new thread. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.