Get gallery with id – PHP – SitePoint Forums

I am creating a simple blog site, by creating a new page I have also inserted an image gallery. the page and the gallery both have two different tables because I couldn’t figure out how to put a gallery in a single table (meaning a gallery section in the page table, so I created two tables)

What I’m trying to achieve in update pages is to check if the image is inserted in the update page or not. if the image is inserted, display the image, else allow the user to upload the image in the update page

table_name = english_version (table for the page)

table_name = english_gallery (table for gallery)

gallery_id image_id image

*Where image_id = id (id of English version)

So, when the user creates a new page and a new element, he is sent to the update page:

so if user forget to insert image for gallery i want to give image upload option in update pages…

    $update_id = intval($_GET['update']);
    $update = $conn->query("SELECT * FROM english_version WHERE id = $update_id ");
    while($rows = $update->fetch(PDO::FETCH_OBJ) ):
        $id = $rows->id;
        $title = $rows->title;
        $content = $rows->content;

check if image is inserted or not

query("SELECT * FROM english_gallery WHERE image_id = $update_id"); while($rows_gal = $gallery->fetch(PDO::FETCH_OBJ) ): $id = $rows_gal->gallery_id; $image_id = $rows_gal->image_id; $image = $rows_gal->image; //check if image_id == $update_id (where $update is id of (primary_key) english_version (table for page)) if($image_id == $update_id ){ ?> $val){ $image_name = $_FILES['images']['name'][$key]; $tmp_name = $_FILES['images']['tmp_name'][$key]; $size = $_FILES['images']['size'][$key]; $type = $_FILES['images']['type'][$key]; $error = $_FILES['images']['error'][$key]; // File upload path $fileName = basename($_FILES['images']['name'][$key]); $targetFilePath = $targetDir . $fileName; // Check whether file type is valid $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); if(in_array($fileType, $allowTypes)){ // Store images on the server if(move_uploaded_file($_FILES['images']['tmp_name'][$key],$targetFilePath)){ $images_arr[] = $targetFilePath; $insert = $conn->query("INSERT into english_gallery (image_id,image) VALUES ('$update_id','$targetFilePath')"); $galleryid = $conn->lastInsertId(); if($insert){ $count = $key + 1; $statusMsg = " ".$count. " image file has been uploaded successfully."; }else{ $statusMsg = "Failed to upload image"; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.'; } }//multiple_image upload starts ?>

if($image_id == $update_id ){

if there is an image, its image is displayed but if there is no image, it does not display the input option for image upload

if think other conditions does not work because $image_id stores id of (primary_key) english_version (table for page)) it checks the id which is never created…

so how can i get the condition, where if the user has inserted an image, the image will be displayed, else the user will have the option to upload image…

Source link

About Irene S. Stroupe

Check Also

Does anyone know RedbeanPHP? – PHP – SitePoint Forums

I’m using RedbeanPHP ORM to design a personal text-based web game. So what I’m trying …