继续收到同样的错误消息
警告:mysqli_error()预计在第29行C:\ xampp \ htdocs \ demetriusdesign777.com \ includes \ functions.php中给出1个参数0 查询失败
<?php
if(isset($_POST['submit'])) {
$db['db_host'] = "localhost";
$db['db_user'] = "root";
$db['db_pass'] = "";
$db['db_name'] = "dd777";
foreach($db as $key => $value) {
define(strtoupper($key), $value);
}
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$username = $_POST['username'];
$email = $_POST['e-mail'];
$phone = $_POST['phone'];
$info = $_POST['info'];
$budget = $_POST['budget'];
$website = $_POST['website'];
$query = "INSERT INTO userinfo(name, email, phone, website, info, budget) ";
$query .= "VALUES ('$username', '$email' '$phone', '$info', '$budget', '$website')";
$result = mysqli_query($connection, $query);
if(!$result) {
die('Query FAILED' . mysqli_error());
} else {
echo "Record Create";
}
}
?>
答案 0 :(得分:2)
mysqli_error()
调用需要一个参数。参数应该是连接句柄。
if(!$result) {
die('Query FAILED' . mysqli_error($connection));
这会告诉您查询中的实际错误,即参数列表部分中'$email' '$phone',
之间缺少的逗号。
$query = "INSERT INTO userinfo
(name, email, phone, website, info, budget)
VALUES
('$username', '$email', '$phone', '$info', '$budget', '$website')";
答案 1 :(得分:1)
'$email'
和'$phone'
mysqli_error($connection)
。需要参数。使用此编辑的代码。
<?php
if(isset($_POST['submit']))
{
$DB_HOST = "localhost";
$DB_USER = "root";
$DB_PASS = "";
$DB_NAME = "dd777";
$connection = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
$username = $_POST['username'];
$email = $_POST['e-mail'];
$phone = $_POST['phone'];
$info = $_POST['info'];
$budget = $_POST['budget'];
$website = $_POST['website'];
$query = "INSERT INTO userinfo(name, email, phone, website, info, budget) ";
$query .= "VALUES ('$username', '$email','$phone', '$info', '$budget', '$website')";
$result = mysqli_query($connection, $query);
if(!$result) {
die('Query FAILED' . mysqli_error($connection));
} else {
echo "Record Create";
}
}
}