Click here to Skip to main content
15,884,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here is the index file

PHP
<?php //Booking Request index file that sends data from the form to the database 
		
		include 'connection.php';
		
		
		// Assigning Variables
		
		$evename = $_POST['event_name'];
		$evedescrip = $_POST['event_description'];
		$evetype = $_POST['event_type'];
		$fac = $_POST['name_of_facility'];
		$startdate = $_POST['event_start_date_time'];
		$enddate = $_POST['event_end_date_time'];
		$evecood = $_POST['event_coordinator'];
		
		// Variable that executes request to send data to database
		$sql = "INSERT INTO booking_requests (`event_name`,`event_description`,`event_type`,
		`name_of_facility`,`event_start_date_time`,`event_end_date_time`,`event_coordinator`)
				VALUES('$evename','$evedescrip','$evetype','$fac','$startdate','$enddate','$evecood')";
		
		// Statement stating whether the execution is successful
		if (!mysqli_query ($link,$sql)){
		die ('Error: ' . mysqli_error($link));
		} 
		else 
		echo ('Entry successfully submitted');
?>



Here is the form

PHP
<?php
		include 'includes/connection.php';
		
?>	
	<!-- HTML form to display text area for event name and event description and to allow user to input date and time -->
	<form id="form1" name="form1" method="post" action="includes/bookingProjectIndex.php">
	<label for="event_name">Enter an event name</label><input type="text" name="event_name" id="event_name" /><br>
	<br class="clear" /> 
	<label for="event_coordinator">Enter the name of the event coordinator</label><input type="text" name="event_coordinator" id="event_coordinator" /><br>
	<br class="clear" /> 
	<textarea name="event_description" id="event_description" cols="45" rows="5">Give a description of the event</textarea>
	<br class="clear" /> 
	Enter an event start date and time:<br>
	<input type="date" name="event_start_date_time" max="3000-01-01">
	<input type="time" name="event_start_date_time"><br><br>
	Enter an event end date and time:<br>
	<input type="date" name="event_start_date_time" min="2015-01-01">
	<input type="time" name="event_start_date_time"><br><br>
	<input type="submit">
	</form>
	
		
 
<?php

		// Get event types from database

		$sql = "SELECT * FROM (event_types)";
		$query = mysqli_query ($link,$sql);
		
		echo "Select an event type:<select name='event_type'>";
		while ($result = mysqli_fetch_array($query, MYSQL_ASSOC)){
		echo "<option value='" .$result['event_type']."'>" . $result['event_type'] . "</option>";
	}
		echo "</select>"; 
		echo "<br></br>";
		
		
		// Get facilities from database
		$sqlt = "SELECT * FROM (facilities)";
		$queryt = mysqli_query ($link,$sqlt);
		
		echo "Select a facility to host event:<select name='name_of_facility'>";
		while ($resultt = mysqli_fetch_array($queryt, MYSQL_ASSOC)){
		echo "<option value='" .$resultt['name_of_facility']."'>" . $resultt['name_of_facility'] . "</option>";
			}
		echo "</select>";
		echo "<br></br>";
?>
Posted
Updated 3-Apr-15 15:14pm
v3

1 solution

Put the select code blocks inside the form, so that it can be submitted. PHP Forms[^]
<form id="form1" name="form1" method="post" action="includes/bookingProjectIndex.php">

<!— other HTML code —>

<?php
 
        // Get event types from database

        $sql = "SELECT * FROM (event_types)";
        $query = mysqli_query ($link,$sql);
 
        echo "Select an event type:<select name='event_type'>";
        while ($result = mysqli_fetch_array($query, MYSQL_ASSOC)){
        echo "<option value='" .$result['event_type']."'>" . $result['event_type'] . "</option>";
    }
        echo "</select>"; 
        echo "<br></br>";
 
        // Get facilities from database
        $sqlt = "SELECT * FROM (facilities)";
        $queryt = mysqli_query ($link,$sqlt);
 
        echo "Select a facility to host event:<select name='name_of_facility'>";
        while ($resultt = mysqli_fetch_array($queryt, MYSQL_ASSOC)){
        echo "<option value='" .$resultt['name_of_facility']."'>" . $resultt['name_of_facility'] . "</option>";
            }
        echo "</select>";
        echo "<br></br>";
?>
<input type="submit" name="Submit> value="Submit">

</form>

However, you should use parameterized query to avoid SQL injection, refer:
1. SQL Injection[^]
2. How can I prevent SQL-injection in PHP?[^]
 
Share this answer
 
v3
Comments
Ray-Rae 4-Apr-15 9:20am    
@PeterLeow its works perfectly thank you !!!!!!!! man
Peter Leow 4-Apr-15 13:15pm    
You are welcome.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900