PDA

View Full Version : PHP help please? :)



Excellent2
25-11-2008, 06:37 PM
I get this error:
Parse error: syntax error, unexpected T_ELSE in /home/name/public_html/derek/email_sub.php on line 15

Code:

<?php

session_start();
include 'includes/db.php';

if (isset($_POST['sub'])) {
if(!$_POST['email']) {
echo "You didn't submit and email!";
} else {
$emails = mysql_query("SELECT * FROM `email`");
$emailss = mysql_fetch_array($emails);
if ($emailss > 1) {
echo "This email is already subscribed to our newsletter!";
}
} else {
$email = htmlspecialchars($_POST['email']);
$add = mysql_query("INSERT INTO `subscribers` (`email`) VALUES('$email')");
echo "Thanks for subscribing to $sitename!";
}
} else {
echo "<form method='post' action='$_SERVER[PHP_SELF]'>
Email:<br>
<input type='text' name='email' size='20'><br>
<input type='submit' name='sub' value='Submit'>
</form>";
}

?>

Joe!
25-11-2008, 06:41 PM
<?php

session_start();
include 'includes/db.php';

if (isset($_POST['sub'])) {
if(!$_POST['email']) {
echo "You didn't submit and email!";
} else {
$emails = mysql_query("SELECT * FROM `email`");
$emailss = mysql_fetch_array($emails);
if ($emailss > 1) {
echo "This email is already subscribed to our newsletter!";
}
else {
$email = htmlspecialchars($_POST['email']);
$add = mysql_query("INSERT INTO `subscribers` (`email`) VALUES('$email')");
echo "Thanks for subscribing to $sitename!";
}
}
}
else {
echo "<form method='post' action='$_SERVER[PHP_SELF]'>
Email:<br>
<input type='text' name='email' size='20'><br>
<input type='submit' name='sub' value='Submit'>
</form>";
}


?>

try that? :)

Tomm
25-11-2008, 06:43 PM
There is no opening if block for the following else block:


} else {
echo "<form method='post' action='$_SERVER[PHP_SELF]'>
Email:<br>
<input type='text' name='email' size='20'><br>
<input type='submit' name='sub' value='Submit'>
</form>";
}

Source
25-11-2008, 06:49 PM
ever heard of indentation?

Calon
25-11-2008, 07:03 PM
You had two ending brackets, so it didn't have anything to check else against

Excellent2
25-11-2008, 07:06 PM
Stupid stupid mistake guys, thanks for the help :) +rep to all.

Want to hide these adverts? Register an account for free!