Click here to Skip to main content
13,795,118 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi I have two forms in one page - one is working, but i was wondering do i do the exact same code as below for the second? both going into two different tables?

Whats the best way around this?

What I have tried:

$UserID = $_SESSION['currentUserID'];
			//insert into database with a prepared statement
			$stmt = $conn->prepare('INSERT INTO MedicalAppointment (Time, Date, Notes, AppointmentType,UserID) VALUES (:Time, :Date, :Notes, :AppointmentType, :UserID)');
			$stmt->execute(array( 
				':Time' =>$_POST['Time'],
				':Date' => $_POST['Date'],	
				':Notes' => $_POST['Notes'],	
				':AppointmentType' =>$_POST['AppointmentType'],
				':UserID' =>$UserID
				));
				
				
		//$UserID = $conn->lastInsertId('UserID');
			ob_start();
			//redirect to index page
			echo'<script>window.location = "Appointments.php?action=saved";</script>';
		
 
			
			//header("Location: index.php?action=joined");
			exit;

		//else catch the exception and show the error.
		} catch(PDOException $e) {
			$error[] = $e->getMessage();
		}
}
	}	
?>
Posted 21-Feb-18 6:59am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If the codes exactly the same then they'll do exactly the same thing. You need to have some method of distinguishing which form to access. If the operations' identical then you need to, perhaps, make the submission a function call so you can pass in a reference to either form.

The way you distinguish forms is to give them ID's and then you can submit them using that difference. You can see more about forms here: HTML Forms[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.181207.3 | Last Updated 21 Feb 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100