开发者

error occurred during data insert in mysql

开发者 https://www.devze.com 2023-01-09 23:31 出处:网络
my code - require \'database.php\'; $uid = $_SESSION[\'UserId\']; $title = $_POST[\'imgtitle\']; $tag = $_POST[\'imgtag\'];

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>开发者_StackOverflow中文版;";
    }

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 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')"; 


make sure all of your POST variables are coming through correctly

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

精彩评论

暂无评论...
验证码 换一张
取 消