Tell me how to make the removal of a picture in a modal window. You need to delete from the database (the path of the picture).
There is a table of images (contains pictures of goods) and the table has 3 fields :
- id - A_U field
- name - (varchar 255) contains the path to the image "/i/20160418.jpg"
- tovars_id - associates a picture with a product. (1 product I can have several pictures)
In general, I have a problem with the removal. The code is written. The problem is this when you click on the picture below (I circled around with a red square in the screenshot) my whole site hangs and nothing can be done, I canβt even see what comes up in the Network tab (Google Chrome browser).
Pictures in a modal window are displayed by foreach loop through php.
$_POST[upload]- ΡΡΠΎ ΠΊΠ½ΠΎΠΏΠΊΠ° ΠΠ°Π³ΡΡΠ·ΠΈΡΡ if($_POST[upload]) { $id=$_POST[id]; $uploaddir = '/i/'; foreach ($_FILES['userfile']['name'] as $m=>$w){ if(($_FILES['userfile']['type'][$m] == 'image/gif' || $_FILES['userfile']['type'][$m] == 'image/jpeg' || $_FILES['userfile']['type'][$m] == 'image/png') && ($_FILES['userfile']['size'][$m] != 0 and $_FILES['userfile']['size'][$m]<=1024000)) { $ex = explode('.',$w); $ex= end($ex); $apend=date('YmdHis').rand(100,1000).'.'.$ex; $uploadfile = "$uploaddir$apend"; if (move_uploaded_file($_FILES['userfile']['tmp_name'][$m], $_SERVER[DOCUMENT_ROOT].$uploadfile)) { $c="INSERT INTO images (name, tovars_id) VALUES('$uploadfile', '$id')"; $query=$dbh->prepare($c); $query->execute(); } } } header("Location: /pr1.php"); exit; /*ΠΠΎΠ΄ Π½ΠΈΠΆΠ΅ ΠΎΡΠ²Π΅ΡΠ°Π΅Ρ Π·Π° ΡΠ΄Π°Π»Π΅Π½ΠΈΠ΅ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ*/ } elseif($_POST[image_delete]){ $id=$_POST[image_id]; $src=$_POST[src]; $c="DELETE FROM `images` WHERE id=$id"; $query1=$dbh->prepare($c); $query1->execute(); } else{ echo"Error2"; } Ajax
$(".modal_images").click(function(){ id=this.dataset.id; //ΠΏΠΎΠ»ΡΡΠ°Ρ id ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ src=this.attributes.src;// ΠΏΠΎΠ»ΡΡΠ°Ρ ΠΏΡΡΡ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ $.ajax({ type: "POST", url: "exit.php", data: {image_id:id, src: src, image_delete: 'true'} , success: function(msg){ alert( "ΠΡΠΈΠ±ΡΠ»ΠΈ Π΄Π°Π½Π½ΡΠ΅: " + msg ); } }); }); HTML & PHP
Here are the pictures from the database.
<? foreach($rows as $k=>$img){ ?> <img id="output_<?=$k?>" data-id="<?=$img[id]?>" class="modal_images" style="height: 100px; width: 100px;" src="<?= $img['name'] ?>"> <?}?>
People help to understand why the page hangs and does not work click on the picture. I do not know how to solve my problem. Maybe the modal window is not suitable for solving this problem or there is another theory.
