doucai5315
2016-11-26 08:22 阅读 6
已采纳

数据库插入不起作用[重复]

This question already has an answer here:

Why is the code below not inserting anything into the database table?

require_once"connection.php";
$target_Path='img/displays/';
$caption=$_POST['caption'];
$albums=$_POST['albums'];
$target_Path = $target_Path.basename($_FILES['photo']['name'] );
move_uploaded_file( $_FILES['photo']['tmp_name'], $target_Path);
$withoutExt = preg_replace("/\\.[^.\\s]{3,4}$/", "", $target_Path);
mysqli_query($connection,"INSERT INTO `ett`.`gallery` (`id` ,`album`,`name`,`path`)VALUES (`NULL`,`".$albums."`,`".$caption."`,`".$withoutExt."`)");                                                                                            

The code below works fine, but for some reasons the query above is not working. What is the problem?

mysqli_query($connection,"INSERT INTO `ett`.`gallery` (`id`, `album`, `name`, `path`) VALUES (NULL, '1', 'test', 'test')");
</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douqian1517 douqian1517 2016-11-26 14:34

    Single quotes should be used around string values, not backticks

    mysqli_query($connection,"INSERT INTO `ett`.`gallery` (`id` ,`album`,`name`,`path`)VALUES (NULL,'".$albums."','".$caption."','".$withoutExt."')"); 
    
    点赞 评论 复制链接分享

相关推荐