私の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
定義されていない理由がわかりません。