Jump to content

Two Forms, one handle.php


Calgaryalberta

Recommended Posts

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";
}
?>

Link to comment
Share on other sites

  • 5 weeks later...

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

 

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.