0

我的 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没有定义。

4

2 回答 2

3
if ($result === FALSE) {
    echo mysqli_error($dbc);
} else {
    echo mysqli_affected_rows($dbc);
}

$ mysql -u root -pmyPassWord DB_NAME

> 从动态中选择标题;

验证某些东西实际上正在进入数据库。

于 2012-04-28T14:38:42.330 回答
2

尝试or die(mysqli_error());在查询后添加:

$result = mysqli_query($dbc, $query) or die(mysqli_error());

这可能会给你一个线索,查询有什么问题。

于 2012-04-28T14:34:50.867 回答