Calgaryalberta Posted March 14, 2008 Share Posted March 14, 2008 I have two html forms on my page. One is for users to enter their email address in the top left corner and hit 'submit' and it adds them to our mailing list. The other form is within a table, and is a login. Instead of having the login use loginhandle.php and the email for use emailhandle.php is it possible just to have one php handle form, for both of these scripts? Right now I have two seperate handle.php for each form. The problem is, when I try and and use the email form it works fine using emailhandle.php, but when I try and use the login and click 'submit' it is looking for emailhandle.php, when it should be looking for loginhandle.php. I will be glad to post the main_page.htm upon request but it is pretty long, for now I have posted the emailhandle.php and the loginhandle.php - Any tips would be great emailhandle.php <?php $con = mysql_connect("****","****","****") or die('Could not connect: ' . mysql_error()); mysql_select_db("login", $con); $sql="INSERT INTO subscribe (email, forename, surname, user) VALUES ('".$_POST['email']."','".$_POST['forename']."','".$_POST['surname']."','".$_POST['mltype']."')"; $query = mysql_query($sql,$con) or die('Error: ' . mysql_error()); if ($query) { echo "You Have Now Been Added To Our Mailing List";mysql_close($con); } else { echo "Not added."; } ?> loginhandle.php <?php $host="****"; // Host name $username="****"; // Mysql username $password="****"; // Mysql password $db_name="****"; // Database name $tbl_name="****"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from signup form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=@mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "members/login_successful.php" session_register("myusername"); session_register("mypassword"); header("location:members/login_successful.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment Share on other sites More sharing options...
Calgaryalberta Posted March 14, 2008 Author Share Posted March 14, 2008 Oh and on my html page, I do have one form looking for emailhandle.php and the other form looking for loginhandle.php But on the login, when clicking the submit button it is looking for emailhandle.php Quote Link to comment Share on other sites More sharing options...
jkewlo Posted March 14, 2008 Share Posted March 14, 2008 yes it is possible you want the page to refer to it self and create the function id say take a look at Jpmaster77 google him his script is a good reference to the functions of the $self Quote Link to comment Share on other sites More sharing options...
JTapp Posted April 14, 2008 Share Posted April 14, 2008 I have the same problem but can't find the reference to Jpmaster 77.. can you post a link? Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 Depends on how you do it... if you have a form building class it would be fairly easy... otherwise you could simply give the submit buttons different names, and on the handle file: if ($_POST['submitLogin']) { // do login handle } elseif ($_POST['submitEmail']) { // do email handle } 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.