The Problem:
I have two forms on one page (inc/form.php and inc/form2.php) which are embedded into a main page via includes. The two forms are the mailing list form and the unsubscribe form. The issue I'm having, ..is that when ever I submit from either one of the forms, ..they BOTH return their response messages upon the <?php echo $PHP_SELF?> action (which is a problem). It seems that no matter what I do, both forms are posting at the same time (or so it seems). Any help would be appreciated!..
Joing Mailing List Form (inc/form.php)
<TABLE BORDER="0" ALIGN=center cellpadding="0">
<TD class="body2">First Name</TD>
<form name="form1" method="post" action="<?php echo $PHP_SELF?>">
<TD><INPUT name=fname TYPE=text size="6" class="tablecell2"></TD>
<TR>
<TD class="body2">Last Name</TD>
<TD><INPUT name=lname TYPE=text size="6" class="tablecell2"></TD>
</TR>
<TR>
<TD class="body2">Email</TD>
<TD><INPUT name=email TYPE=text size="6" class="tablecell2"></td>
<INPUT TYPE="hidden" name="stage" value="process">
</tR>
<TR>
<TD colspan=2 align=center><br>
<INPUT TYPE=submit class="tablecell2" value="Sign up Now!"></TD>
</form></tR>
</TABLE>
The above form is included in the below script via require (maillist.php)
<?
require('inc/config.php');
include('inc/form.php');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
insert_mail();
}
?>
The Unsubscribe Area Form (inc/form2.php)
<TABLE BORDER=0 ALIGN=center>
<form name="form2" method="post" action="<?php echo $PHP_SELF?>"><TR>
<TD class="body2">Email</tD>
<TD><INPUT name=email TYPE=text size="6" class="tablecell2"></td>
</tR>
<TR>
<TD colspan=2 align=center><INPUT TYPE=submit value=unsubscribe class="tablecell2"></TD>
</tR></FORM></TABLE>
The above form is included in the below script via require (unsubscribe.php)
<?
require('inc/unsubscribe.php');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
delete_mail("POST");
}
if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($_GET['email'] == "") {
include('inc/form2.php');
} else {
delete_mail("GET");
}
}
?>
Config.php
$usernam=""; // MySQL username
$pass=""; // MySQL Password
$db="FreePhpNet"; // MySQL database
$conn = mysql_connect("localhost", "$usernam", "$pass") or die("Invalid server or user."); // Connects to MySQL Database
mysql_select_db("$db", $conn);
function insert_mail() {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$sql2="select * from mail where email='$email'";
$result2=mysql_query($sql2) or die("select fails");
$no=mysql_num_rows($result2);
if ($no==0) {
$sql = "insert into mail(id,fname,lname,email) values(NULL,'$fname','$lname','$email')";
$result = mysql_query($sql) or die("insert fails");
echo "Email added to list: " . LISTNAME;
} else {
echo "Email Address Already Exists in List: " . LISTNAME;
}
}
function delete_mail() {
$email = $_POST['email'];
if ($email == "") {
$email = $_GET['email'];
}
$sql2="select * from mail where email='$email'";
$result2=mysql_query($sql2) or die("select fails");
$no=mysql_num_rows($result2);
if ($no==0) {
echo "Your email was not found in the list: " . LISTNAME;
} else {
echo "Your email was unsubscribed from the list: " . LISTNAME;
}
$sql2="delete from mail where email='$email'";
$result2=mysql_query($sql2) or die("unsubscribe failed, please try again");
}
?>