Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is what i currently have

This is the html form

HTML
<form id="form1" name="form1" method="post" action="includes/facilityProjectIndex.php">
<label for="name_of_facility">Name Of Facility</label><input type="text" name="name_of_facility" id="name_of_facility" />
<br class="clear" /> 
<label for="location">Location</label><input type="text" name="location" id="location" />
<br class="clear" /> 
<label for="responsible_organisation">Responsible Organisation</label><input type="text" name="responsible_organisation" id="responsible_organisation" />
<br class="clear" /> 
<input type="submit" name="Submit" id="Submit" value="Submit" />
<br class="clear" /> 
</form>


And this is the php index file



PHP
<?php //Facility index file that sends data from the form to the database 
	

include 'connection.php';
	
	// Assigning Variables
	$name = $_POST['name_of_facility'];
	$location = $_POST['location'];
	$responorg = $_POST['responsible_organisation'];	
	
	// Variable that executes request to send data to database 
	$sql = "INSERT INTO facilities (name_of_facility,location,responsible_organisation)
			VALUES('$name','$location','$responorg')";
	
	// Statement stating whether the execution is successful 
	if (!mysqli_query ($link,$sql)){
		die ('Error: ' . mysqli_error($link));
	} 
	else 
		echo ('Entry successfully submitted');
?>



Any help please !
Posted
Comments
Peter Leow 3-Apr-15 11:49am    
Any error message?

add backticks

PHP
<?php //Facility index file that sends data from the form to the database

include 'connection.php';

<pre>
// Assigning Variables
$name = $_POST['name_of_facility'];
$location = $_POST['location'];
$responorg = $_POST['responsible_organisation'];

// Variable that executes request to send data to database
$sql = "INSERT INTO facilities (`name_of_facility`,`location`,`responsible_organisation`)
        VALUES('$name','$location','$responorg')";

// Statement stating whether the execution is successful
if (!mysqli_query ($link,$sql)){
    die ('Error: ' . mysqli_error($link));
}
else
    echo ('Entry successfully submitted');
 
Share this answer
 
Comments
Peter Leow 3-Apr-15 11:58am    
Backticks are only needed when using reserved words or space in field name.
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
 
v2

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