Skip to content

Instantly share code, notes, and snippets.

@Kingo4luv
Created February 19, 2018 23:09
Show Gist options
  • Save Kingo4luv/ea1da4ddb92f3e45775433be27c33d8e to your computer and use it in GitHub Desktop.
Save Kingo4luv/ea1da4ddb92f3e45775433be27c33d8e to your computer and use it in GitHub Desktop.
This php file processes the form and send the collected data into the database
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "training");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Check if submit button is clicked
if(isset($_POST['submit'])){
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
// attempt insert query execution
$sql = "INSERT INTO users (first_name, last_name) VALUES ('$first_name', '$last_name')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
// close connection
mysqli_close($link);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment