我的PHP脚本如下:
<?php
require_once('connectvars.php');
$file = $_FILES['image']['name'];
$target = GW_UPLOADPATH . $file;
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$dbc = mysqli_connect(DB_HOST, DB_UN, DB_PW, DB_NAME) or die('Error connecting to the MySQL server');
$title = mysqli_real_escape_string($dbc, trim($_POST['title']));
$description = mysqli_real_escape_string($dbc, trim($_POST['content']));
$host = mysqli_real_escape_string($dbc, trim($_POST['host']));
$duration = mysqli_real_escape_string($dbc, trim($_POST['duration']));
$sn1 = mysqli_real_escape_string($dbc, trim($_POST['link1']));
$sn2 = mysqli_real_escape_string($dbc, trim($_POST['link2']));
$sn3 = mysqli_real_escape_string($dbc, trim($_POST['link3']));
$sn4 = mysqli_real_escape_string($dbc, trim($_POST['link4']));
$sn5 = mysqli_real_escape_string($dbc, trim($_POST['link5']));
$query = "INSERT INTO dyhamb (title, description, host, duration, file, sn1, sn2, sn3, sn4, sn5 ) VALUES ('$title', '$description', '$host', '$duration', '$file', '$sn1', '$sn2', '$sn3', '$sn4', '$sn5')";
$result = mysqli_query($dbc, $query);
if (!$result) {
echo 'failed';
} else {
echo 'success';
}
mysqli_close($dbc);
}
?>
当我运行脚本时,我收到“失败”,我无法解决原因。 $dbc
和$query
似乎都很好,因此不确定为什么$result
未定义。
答案 0 :(得分:3)
if ($result === FALSE) {
echo mysqli_error($dbc);
} else {
echo mysqli_affected_rows($dbc);
}
另外
$ mysql -u root -pmyPassWord DB_NAME
&GT;从dynamb中选择标题;
验证某些内容实际进入数据库。
答案 1 :(得分:2)
尝试在查询后添加or die(mysqli_error());
:
$result = mysqli_query($dbc, $query) or die(mysqli_error());
这可能会为您提供查询错误的线索。