2016-11-26 165 views
0

为什么下面的代码不向数据库表中插入任何内容?数据库插入不起作用

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

用来看看到你的HTTP服务器错误日志文件,_read_完全问题,而不必_guess_什么。 – arkascha

+0

回应查询,并尝试写入直接数据库,以便您可以确认查询是否正确 – Deep

+0

为什么id始终为空? –

回答

0

单引号应该围绕字符串值,而不是反引号

mysqli_query($connection,"INSERT INTO `ett`.`gallery` (`id` ,`album`,`name`,`path`)VALUES (NULL,'".$albums."','".$caption."','".$withoutExt."')"); 
+0

Qirel提供的链接有更多信息。请参考,即使这可以解决您的问题 – jophab

+0

谢谢你们,链接和你的答案都是有用的 –

+0

@MustafaAzad欢迎:) – jophab