Hey, I'm new to mysql and am having trouble with adding information to a database. Error "Data Not Inserted Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in... on line 56. How can I fix this? Thanks.
<?php
if(isset($_POST['submit']))
{
$hostname = "localhost";
$username = "";
$password = "";
$databaseName = "";
$title = $_POST['title'];
$first_name = $_POST['first_name'];
$surname = $_POST ['surname'];
$gender = $_POST ['gender'];
$dob = $_POST ['dob'];
$street_address = $_POST ['street_address'];
$suburb = $_POST ['suburb'];
$state = $_POST ['state'];
$home_phone = $_POST ['home_phone'];
$mobile_phone = $_POST ['mobile_phone'];
$work_phone = $_POST ['work_phone'];
$email = $_POST ['email'];
$martial_status = $_POST ['martial_status'];
$occupation = $_POST ['occupation'];
$parent_name = $_POST ['parent_name'];
$preferred_dr = $_POST ['preferred_dr'];
$medicare_no = $_POST ['medicare_no'];
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$query = "INSERT INTO `Patient Details Table` (`Title`, `First Name`, `Surname`, `Gender`, `D.O.B`, `Street Address`, `Suburb`, `State`, `Home Phone`, `Mobile Phone`, `Work Phone`, `Email`, `Martial Status`, `Occupation`, `Parent Name`, `Preferred Dr`, `Medicare No.`) VALUES ('$title', '$first_name', '$surname', '$gender', '$dob', '$street_address', '$suburb' '$state', '$home_phone', '$mobile_phone', '$work_phone', '$email', '$martial_status', '$occupation', '$parent_name', '$preferred_dr', '$medicare_no')";
$result = mysqli_query($connect,$query);
if($result)
{
echo 'Data Inserted';
}
else{
echo 'Data Not Inserted';
}
mysqli_free_result($result);
mysqli_close($connect);
}
?>
What I have tried:
The code was originally off a video on how to add inputted information into databases. I have made a few changes in order for it to suit my needs. However, I cannot get it working. Any help you be great. Thanks.