i have this PHP Code:
$sql="SELECT * from project_gallery where sequence = '".$_POST["project_sequence"]."' ";
$rs=mysql_query($sql,$conn);
$project=mysql_fetch_array($rs);
$images = explode(',',$project['images']);
$images = "," . $images . ","; // add comma to beginning and end of list
foreach ($images_to_delete as $image_to_delete)
{
str_replace("," . $image_to_delete . ",", ","); // e.g. replaces ",image1.jpg," with ","
}
$images = substr($images, 1, -1); // remove comma from beginning and end
echo $images;
i want to be able to remove the selected (in the previous HTML Form) part of a string from a cell in my MySQL Table.
in my table my image filenames are stored like:
[image1.jpg],[image2.jpg],[image3.jpg],[image4.jpg]
etc...
so if the checkbox for image2.jpg is checked and the form is submitted, i want to make the string look like:
`[image1.jpg],[image3.jpg],[image4.jpg]`
here is my HTML Form too:
<?php
$sql="SELECT * from project_gallery where sequence = '".$_GET["project"]."' ";
$rs=mysql_query($sql,$conn);
$project=mysql_fetch_array($rs);
$images = explode(',',$project['images']);
?>
<form action="edit.php?project=<?php echo $_GET["project"]; ?>" method="post" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>Project Name</strong><br />
<input type="text" name="project_name" value="<?php echo $project["name"]; ?>" style="width:100%;" /></td>
</tr>
<tr>
<td><strong>Add New Images</strong><br /><input type="file" name="images[]" multiple="multiple" /></td>
</tr>
<?php
foreach($images as $image)
{
$display_image = substr($image, 1, -1);
?>
<tr>
<td><img src="/img/project-gallery/<?php echo $display_image; ?>" width="160px" /><br />
<input type="checkbox" name="images_to_delete[]" id="images_to_delete[]" value="<?php echo $display_image; ?>" /></td>
</tr>
<?php
}
?>
<tr>
<td><input type="text" name="project_sequence" id="project_sequence" value="<?php echo $project["sequence"]; ?>" />
<input type="submit" name="submit" id="submit" value="Save Project" /></td>
</tr>
</table>
</form>