我想连接到一个名为ranch的数据库(带xampp),并在此db中插入一些表单数据。浏览器显示错误:
警告:mysqli_error()期望参数1为mysqli,给定字符串 在第38行的C:\ xampp \ htdocs \ project1 \ register.php
错误:无法执行INSERT INTO child_parent( 'childname', 'childsurname', '年龄', '性别', '名', '姓', '地址', '传统知识', '城市', '电话', '移动', '电子邮件', 'parea', '通') VALUES( '尼科斯', '广告', '34', 'Αγόρι', 'SDS', 'SDS', 'DSD', '34', 'DSDS', '34', '434','邮件@ 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);
}
}
?>
答案 0 :(得分:4)
您的代码存在三个主要问题:
要逐一解决这些问题,请阅读以下三个有用的答案: