Created
February 19, 2018 23:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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