I have created a function called set_title(), which is used to set the title and description in the database I don't know where I was wrong
function set_title($file,$title = "",$description = ""){
$pathinfo = pathinfo($file);
$file = $pathinfo['basename'];
if ($title == "") {
$title = ucfirst($pathinfo['filename']);
}
if ($description !== "") {
$description = mb_substr($description, 0, 150);
}
$sql = "SELECT file, title ,description FROM title WHERE file = '$file'";
$con = new mysqli('localhost','root','','jbstore');
$result = $con->query($sql);
if($result->num_rows > 0){
$data = $result->fetch_assoc();
if($data['description'] == ""){
$sql = "INSERT INTO title (description) VALUES('$description')";
$con->query($sql);
}
}elseif ($result->num_rows == 0) {
$sql = "INSERT INTO title (file,title,description) VALUES ('$file','$title',$description)";
$result = $con->query($sql);
}
}
I expected it insert data into database but nothing happens