I have written this code to upload an item but the insert query is not working.
<?php
require("connect.php");
if(isset($_POST['submit'])) {
move_uploaded_file($_FILES['file']['tmp_name'],"assets/img/portfolio/".$_FILES['file']['name']);
$filename=$_FILES['file']['name'];
if($filename == ''){
echo "you didn't select any image!";
exit;
}
$title = $_POST['title'];
$desc = $_POST['desc'];
$cat = $_POST['category'];
echo "$title, <br>$filename<br>$desc<br>$cat";
$sql = "INSERT INTO portfolio (Title, Img, Desc, Category) VALUES ('$title' ,'$filename' ,'$desc', '$cat')";
if(mysqli_query($conn, $sql)){
echo "<script>alert('You have Successfully added an item')</script>";
}
else{
echo "<script>alert('Failed. Please try again')</script>";
}
}
mysqli_close($conn);
?>
i have tried assigning a select query on $sql and it works. Please help
i found out that the word Desc which i had put as a row is a reserved keyword for Mysql. Thanks for your advice anyway.