我的代码 -
require 'database.php';
$uid = $_SESSION['UserId'];
$title = $_POST['imgtitle'];
$tag = $_POST['imgtag'];
$date = date("d-m-y");
$q = "INSERT into album (`o_id`, `title`, `src`, `tag`, `date`)
VALUES('$uid', '$title', '$image_name', '$tag', '$date'";
$result = $mysqli->query($q) or die(mysqli_error($mysqli));
if ($result)
{
echo "<h1>File Uploaded Successfully! Upload more...!</h1>";
}
我的database.php
-
<?php
$db_name = "szdb";
$db_server = "localhost";
$db_user = "root";
$db_pass = "";
$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error());
?>
错误 -
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
答案 0 :(得分:4)
你最后错过了一个结束括号。
更改
$q = "INSERT into album (`o_id`, `title`, `src`, `tag`, `date`)
VALUES('$uid', '$title', '$image_name', '$tag', '$date'";
到
$q = "INSERT into album (`o_id`, `title`, `src`, `tag`, `date`)
VALUES('$uid', '$title', '$image_name', '$tag', '$date')";
答案 1 :(得分:0)
确保所有POST变量都正确通过
$userid = isset($_POST['userid']) && !empty($_POST['userid']) ? $_POST['userid'] : null;