Skip to content

jmathtech/Customer-PHP-Form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Customer-PHP-Form

A customer form written in PHP.

How to install

  • First, you will need a SQL server to import the 'customers.sql file found in the repository. (Try WAMPserver, Apache server, or any web hosting site)
  • Open the 'cusSubmit.php' file to enter your database information in the mysqli_connect on line 13.
$con = mysqli_connect("localhost", "root", "", "CIS224_php");
  • Upload the files to your FTP or type in localhost:PORT.
  • Find the 'cusForm.php' in your directory.

What I've learned

  • Using variables in PHP to connect to the SQL database. NOTE: If you wish to change or add more variables to the PHP, you will have to update your SQL customer table as well.
 	$firstName = $_POST["fn"];  
	$lastName = $_POST["ln"];  
	$email = $_POST["em"];
	$address = $_POST["ad"];
  • 'INSERT INTO' is used input those variables onto the customers table.
$sql = "INSERT INTO customers (FirstName, LastName, Email, Address)
	VALUES('$firstName', '$lastName', '$email', '$address')";
  • Create an error message if the data fails to connect to the SQL database
if(!$con)
	{
	die("Connection unsuccessful: " . mysql_error());
	// stops the program if the connection is unsuccessful and displays the error message.
	}
  • If the connection is successful, then the php script will echo "System Updated!". If the connection is unsuccessful, I have added an error handler.
if(mysqli_query($con, $sql)) // function that runs the query. Needs the two arguments.
	{
	echo "System updated!";
	}
else 
	{
	echo "Error!" . mysqli_error($con);
	}
	
  • Closing and securing the database connection after a new record has been initiated.
mysqli_close($con);

Example Screenshots

cusform cus_SQL