简体   繁体   中英

error occurred during data insert in mysql

my code -

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>";
    }

my 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());

?>

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 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

You are missing a closing bracket at the very end.

Change

$q = "INSERT into album (`o_id`, `title`, `src`, `tag`, `date`) 
VALUES('$uid', '$title', '$image_name', '$tag', '$date'"; 

to

$q = "INSERT into album (`o_id`, `title`, `src`, `tag`, `date`) 
VALUES('$uid', '$title', '$image_name', '$tag', '$date')"; 

确保所有POST变量都正确传递

$userid = isset($_POST['userid']) && !empty($_POST['userid']) ? $_POST['userid'] : null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM