My sql query does not return results when I use a WHERE id = something, thought the value provided is not NULL or zero

PHP and MySQL

Hello,

I have a MySQL table called “weddings”, containing “id” – int, primary key, Auto_increment, “male_name”, “female_name”, “year” and “file” (PDF file name containing the wed certificate)

I have a form with checkboxes for each wed from the table. Each checkbox has the record id as “id” and the record’s filename(e.g. filename.pdf) as it’s value. The user selects which wed one wants to delete (delete the record from the table and the PDF file from the server – which is constructed like “filename_recordID.pdf” (for the record with id 5, the file name from DB and from server is filename_5.pdf)

What works:
The data from the form is retrieved ok. The delete is ok (for the record in the DB and for the file on the server).

What doesn’t work:
I want to display for the user the female_name and the male_name for the record that the file on the server had an error when deleting (I have 2 PDF that have errors and I use them as tests everytime for this). Aditionally, I want to display an error code: for the undeleted files from server, the error code will be “filename_without_extension_SRV”. (for the record with id 10, it will look like “wed_10_SRV”)

(I will do the same with records that cannot delete from DB, if case: display for the user the female_name and the male_name and the error code, for the record with id 10, it will look like “wed_10_DB”)

Each file (on the server and the name in the DB will be like: wed_<wed_id>.pdf (my php script modifies like this each uploaded file)

undeleted_weds_serv = Array containing the IDs of the records that were undeleted from the server (the corresponding PDF file didn’t delete on the server)

length_undeleted_serv = length of the Array

undeleted_weds_serv Array contains the records ids of the weds that couldn’t be erased from the server and contains 0 for the weds that deleted successfully from the server (the PDF file of the wed)

The Array and the length are constructed ok (I echoed the Array and it’s length and it’s constructed ok).

My code below:

//1. deleting the file from the server
    
// Path to the directory containing files
$directory_path = '../../Continut_site/Primaria/Birouri/Evidenta_persoane/publicatii_casatorie/2024_teste';
    
// Full path to the file
$file_path = $directory_path . '/' . $fisier;
    
// Check if the file exists and delete it
    
if (unlink($file_path)) {
    //array-ul cu id-urile casatoriilor STERSE de pe server
    $casatorii_Sterse_serv[] = $wed_id;
                 
    //array-ul cu id-urile casatoriilor nesterse de pe server
    $undeleted_weds_serv[] = 0;
} else {
    //array-ul cu id-urile casatoriilor nesterse de pe server    
    $undeleted_weds_serv[] = $wed_id;
}
             
//END deleting file from the server 
             
//2. deleting the file from the DB   

$sql = "DELETE FROM weddings WHERE id = $wed_id";
             
if (mysqli_query($con, $sql)) {
    //echo "Record deleted successfully";
            
    //array containing the ids of the deleted weds (from the DB)
    $db_deleted_weds[] = $wed_id;
            
    //array containing the ids of the UNDELETED weds (from the DB)
    $db_undeleted_weds[] = 0;
} else {
    //array containing the ids of the UNDELETED weds (from the DB)
    $db_undeleted_weds[] = $wed_id;
}
         
//END deleting the file from the DB 
             
}//end FOREACH (loop through $_GET array)       
        
//length of the array containing the ids of the records that their corresponding files were deleted from server - OK
$length_undeleted_serv = count($undeleted_weds_serv); 
        
//length of the array containing the ids of the records that their corresponding files were deleted from server - OK
//$length_deleted_db = count($db_undeleted_weds);
        
//echo "length_undeleted_serv: $length_undeleted_serv - OK";
//echo "length_deleted_serv: $length_deleted_serv - OK";
        
for($i=0; $i < $length_undeleted_serv; $i++){
    //echo "(serv) $undeleted_weds_serv[$i]<br>";
    if($undeleted_weds_serv[$i]){
        echo "(nesters serv) ".$undeleted_weds_serv[$i]."<br>";
            
        $sql_undeleted_weds_serv = "SELECT * FROM `weddings` WHERE `id` = '$undeleted_weds_serv[$i]'";
    
        $result_undeleted_weds_serv = mysqli_query($con, $sql_undeleted_weds_serv);
                  
        //cauta in BD numele persoanelor nesterse pentru afisare
        while($record = mysqli_fetch_array($result_undeleted_weds_serv)){
            $male_name = $record['male_name'];
            $female_name = $record['female_name'];
            $db_file = $record['fis']; //file name from the BD (it exists on the server with the same name)
            
            // Remove the extension of the file (use it's name as an error code displayed at the user)
            $filename_without_ext = substr($db_file, 0, strrpos($db_file, "."));
            
            //end remove file extension
            
            echo "<br><br>   ❌ An error occured in <i>".$male_name."</i> și <i>".$female_name."</i> <font color='#f26b1e'> ⇒ "." Error code: <b>".$filename_without_ext."_SRV"."</b></font>"."⚠️";
            
        }//end WHILE    
        
        if (mysqli_num_rows($result_undeleted_weds_serv) > 0) {
            // output data of each row
            while ($row = mysqli_fetch_assoc($result_undeleted_weds_serv)) {
                echo "id: " . $row["id"] . " - Name: " . $row["name"] . "<br>";
            }
        } else {
            echo "0 results";
        }   
    }else{
        echo "<br>   ✅ Was deleted <i>".$male_name."</i> și <i>".$female_name."</i> (".$db_file.") <br><br>";
    }//end if_1     
}//end FOR looping through the Array 

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật