【发布时间】:2015-10-06 09:48:57
【问题描述】:
我想连接到一个名为牧场的数据库(使用 xampp)并将一些表单数据插入到这个数据库中。浏览器显示错误:
警告:mysqli_error() 期望参数 1 为 mysqli,给定字符串 在 C:\xampp\htdocs\project1\register.php 第 38 行
错误:无法执行 INSERT INTO child_parent('childname','childsurname','age','gender','name','surname','address','tk','city','telephone','mobile','email', 'parea','通过') VALUES('nikos','ads','34','Αγόρι','sds','sds','dsd','34','dsds','34','434','mail@hotmail .com','sds','34')。
我有下面的 .php 文件。 我该如何解决?
<?php
ini_set('display_errors', 'On');
session_start();
unset ($msg);
echo "kajsj<br>";
$conn= new mysqli("localhost","root","","ranch");
if (mysqli_connect_errno())
{ printf("Connect failed: %s\n",mysqli_connect_error());//error message
}
else
{
printf("Connect achieved<br>");
echo $_GET['childname'];
$childname=$_GET['childname'];
$childsurname=$_GET['childsurname'];
$age=$_GET['age'];
$gender=$_GET['gender'];
$name=$_GET['name'];
$surname=$_GET['surname'];
$address=$_GET['address'];
$tk=$_GET['tk'];
$city=$_GET['city'];
$telephone=$_GET['telephone'];
$mobile=$_GET['mobile'];
$email=$_GET['email'];
$parea=$_GET['parea'];
$pass=$_GET['pass'];
// Insert data into mysql
$query1="INSERT INTO child_parent('childname','childsurname','age','gender','name','surname','address','tk','city','telephone','mobile','email','parea','pass')
VALUES('$childname','$childsurname','$age','$gender','$name','$surname','$address','$tk','$city','$telephone','$mobile','$email','$parea','$pass')";
if(mysqli_query($conn, $query1))
{echo "Records added successfully.";
}
else{echo "ERROR: Could not able to execute $query1. " . mysqli_error($query1);
}
}
?>
【问题讨论】:
-
mysql_fetch_array() expects parameter 1 to be resource (or mysqli_result), boolean given 可能重复欢迎。但请记住在提问之前进行简单的搜索。这个问题之前一定被问过 1000 次。