为什么以下代码没有在数据库表中插入任何内容?
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."`)");
以下代码运行正常,但由于某些原因,上面的查询无效。有什么问题?
mysqli_query($connection,"INSERT INTO `ett`.`gallery` (`id`, `album`, `name`, `path`) VALUES (NULL, '1', 'test', 'test')");
答案 0 :(得分:0)
单引号应该用在字符串值周围,而不是反引号
mysqli_query($connection,"INSERT INTO `ett`.`gallery` (`id` ,`album`,`name`,`path`)VALUES (NULL,'".$albums."','".$caption."','".$withoutExt."')");