Your code:
$firstname = isset($link, $_POST['FirstName'])? $_POST['$firstame'] : '';
My Code:
$firstname = isset($_POST['FirstName']) ? mysqli_real_escape_string( $link, $_POST["FirstName"] ) : '';
From the ducumentation: For more information, visit here: http://php.net/manual/en/function.isset.php
isset — Determine if a variable is set and is not NULL
bool isset ( mixed $var [, mixed $... ] )
In $_POST after ? in your code, you have passed the variable which will return ''; And hence, you are not seeing that the values are inserted in the database.
So your code should look like this:
<?php
error_reporting(E_ALL ^ E_NOTICE);
$link = mysqli_connect( 'localhost', '****', '******', 'pet_shop');
if( !$link ) {
die( "ERROR: Could not connect: " . mysqli_connect_error( $link ) );
}
//You need to use mysqli_real_escape_string() method to avoid sql injection;
// Refer this link for more information http://php.net/manual/en/mysqli.real-escape-string.php
$firstname = isset( $_POST['FirstName'] ) ? mysqli_real_escape_string( $link, $_POST['FirstName'] ) : '';
$lastname = isset( $_POST['LastName'] ) ? mysqli_real_escape_string( $link, $_POST['LastName'] ) : '';
$address = isset( $_POST['Address'] ) ? mysqli_real_escape_string( $link, $_POST['Address'] ) : '';
//and so on...
$sql = "INSERT INTO `pet_shop`.`grooming` (`FirstName`, `LastName`, `Address`, ... ) VALUES ( ' " . $firstname . " ', ' " . $lastname . " ', ' " . $address . " ' , ...)";
$result = $mysqli_query( $link, $sql );
if( $result ) {
// remove the echo line or else you will face a warning of cannot modify header.
// You can create a new file and write the echo statement in that file
// You can then call that file in the header function below.
echo "A member of our staff will contact you to set up an appointment..";
// To avoid twice insertion in the database on page refresh
header("Location: /path/to/your/file.php");
// To stop the execution of the current page.
exit();
} else {
echo "ERROR: Could not execute the query. " . mysqli_error( $link );
}
mysqli_close( $link );
?>