警告:mysqli_free_result()期望参数1为mysqli_result,boolean在...中给出 [英] Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in...
问题描述
嘿,我是mysql的新手,在向数据库添加信息方面遇到了麻烦。错误数据未插入警告:mysqli_free_result()期望参数1为mysqli_result,布尔值在第56行的......中给出。我该如何解决这个问题?谢谢。
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
// php code to Insert data into mysql database from input text
if(isset($_POST['submit']))
{
$hostname = "localhost";
$username = "";
$password = "";
$databaseName = "";
// get values form input text and number
$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'];
//$allergies = $_POST ['allergies'];
//$postcode = $_POST ['postcode'];
// connect to mysql database using mysqli
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
// mysql query to insert data
$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')";
//$query = "INSERT INTO `Postcode Table` (`Suburb`, `Postcode`) VALUES ('$suburb', '$postcode')";
//$query = "INSERT INTO `Allergy Table` (`Allergy`) VALUES ('$allergies')";
$result = mysqli_query($connect,$query);
// check if mysql query successful
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.
推荐答案
_POST [' submit']))
{
_POST['submit'])) {
hostname = localhost;
hostname = "localhost";
用户名 = 跨度>;
username = "";
这篇关于警告:mysqli_free_result()期望参数1为mysqli_result,boolean在...中给出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!