0

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')");
Patrik
  • 2,695
  • 1
  • 21
  • 36

1 Answers1

0

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."')"); 
jophab
  • 5,356
  • 14
  • 41
  • 60