I have a form and it works, and the page for writing the text to a file works...with one exception.
The email check (which I blatantly ripped from a tutorial) constatntly returns the failed message.
What stupid logic error have I made?
Code: Select all
<?php
$fp = fopen('news.txt','a');
if ($fp=="") {
echo "Sorry couldn't open file<br>";
} else {
if ($_POST['images']=="") {
echo "<div class=\"button1\">please <a class=\"button1\" href=\"javascript:history.go(-1)\">
<b>go back</b></a>and add image link.<BR><i>go on</i>.</div>\n\n";
} else {
if ($_POST['news']=="") {
echo "<div class=\"button1\">please <a class=\"button1\" href=\"javascript:history.go(-1)\">
<b>go back</b></a>and add some details.<BR><i>the details are important</i>.</div>\n\n";
} else {
if(strstr($_POST["news"],"&")) {
echo "the text cannot contain the ampersand symbol - &";
} else {
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
echo "the email address is invalid";
} else {
if(!strstr($_POST["images"],"[img]")) {
echo "the images link must be formatted correctly<br>ie - contain ''";
}else {
$line = date("d.m.y") . "¬" . $_POST['name'] . "¬".$_POST["email"] . "¬".trim($_POST["subject"]). "¬".$_POST["url"]. "¬".$_POST["images"];
$line .= "¬" . $_POST['news'];
$line = str_replace("\r\n","<BR></BR>",$line);
$line = str_replace(" < "," LESS THAN ",$line);
$line = str_replace(" > "," GREATER THAN ",$line);
$line = str_replace(" >= "," GREATER THAN OR EQUAL TO ",$line);
$line = str_replace(" <= "," LESS THAN OR EQUAL TO ",$line);
$line = str_replace(" & "," and ",$line);
$line = str_replace("&","and",$line);
$line = stripslashes($line);
$line .= "\r\n";
fwrite($fp, $line);
echo "all sorted...cool<br><a href=\"javascript:self.close()\"><small>close window</small></a>";
}
}
}
}
}
}
if(!fclose($fp)) {
}
?>