Reputation: 191
EDIT : I might just make it a more 'step-by-step' process i.e.
Seeing as it feels more user-friendly & it's only for <5 images. I have read & appreciate all of the help that I have received so far.
I'm fairly new to PHP & I'm building a basic PHP image editor which may allow multiple image data auditing which is then inserted into a MySQL database. A limit of 5 images may be uploaded at a time for this system (implying that there will only be a low amount of records to play with), but I'll get to that further down.
GUI:
Some of the data columns used:
All images are echo'd in a while loop by a previous 'SELECT *' result set. Each image will have the 'image id' echo'd inside each input name, so output will be for example:
caption-2, description-2, published-2, imageposition-2, caption-3, description-3
Also, the data values from the previous resultset are echo'd into the input value, allowing the client to edit the current data that exists in the database. There is only one submit button.
My question:
I want to be able to post all of the modified image(s) data to a processor.php form which will then allow me to insert it as an INSERT sql string into the MySQL images table. I need the PHP to be dynamic incase:
If there is an easier way of doing any of the above, I am welcome to new ideas/opinions. Sorry in advance for my poor understanding of PHP.
Upvotes: 0
Views: 213
Reputation: 829
To delete the records easily :
<form action="processor.php" method="post">
<?php
foreach ($images as $img) { // assuming $images is the result set of your sql query
?>
<input type="text" name="name<?php $img['image_id'];?>" value="<?php $img['caption'];?>">
<input type="text" name="desc<?php $img['image_id'];?>" value="<?php $img['description'];?>">
...
<a href="http://yoursiteurl/deleteimg.php?id=<?php $img['image_id']?>">
<?php } ?>
</form>
In deleteimg.php :
<?php
$del = $_POST[id];
$query = $msqli->prepare("DELETE FROM imagetablename WHERE image_id=?");
$query->bind_param( 's', $del );
$query->;execute();
?>
Updating and adding new rows may involve javascript, and much more harder.
Upvotes: 0
Reputation: 4146
Once you get result from 'select *' statement you do foreach
foreach ($images as $image) {
?>
<img src="imagesrc">
<input type="text" name="title_<?php echo $image['image_id'] ; ?>" value="<?php echo $image['title']; ?>">
<input type="text" name="desc_<?php echo $image['image_id'] ; ?>" value="<?php echo $image['description']; ?>">
<input type="button" onclick="markDeleted('<?php echo $image['image_id'] ; ?>')">
<?php } ?>
.....
Once you receive the post value you can explode with "_" and you will get the Primary key and you can update the image table with image ID.
In the javascript function markDeleted
you can set the primary key in some hidden field and sent to process.php.
Add it like comma separated 1,2,3 like this (Split by comma in action page)
function markDeleted (imageId)
{
document.getElementById('deleted_image_ids').value = imageId + ","
}
Upvotes: 1