/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Problem with selecting and deleting multiple database entries

I am working on a gallery that allows a user to upload and delete pictures. So far I have the uploading working fine but have had various problems with deleting. My idea is to have a form with all the pictures showing and each one having a check box. The problem i’ve had is getting more than one picture to delete. Is there a special way to handle checkboxes. I can’t find my code at the moment ( I might have deleted it in frustration) but will post it when I do find it/ re-do it.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@sanchez_1960Mar 12.2008 — Use input boxes to post the id numbers of the each image. The input boxes can be can be named id, and then echo the $i of your loop.

Then on the POST loop through the values and execute the query for every id.
Copy linkTweet thisAlerts:
@roondogauthorMar 12.2008 — this is my code

[code=php]
<?php
$con = mysql_connect("localhost","******","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("******", $con);

$picture = $POST_[delete_picture];

mysql_query("DELETE FROM delete WHERE img_name = $picture");


mysql_close($con);
?>
[/code]


and for the form

[code=php]
<html>
<body>
<form action='delete.php' method='post'>
<?php
$con = mysql_connect("localhost","******","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("*******", $con);

$result = mysql_query("SELECT * FROM delete");

while($row = mysql_fetch_array($result))
{
echo "<img src='".$row['img_name']."' alt='image' />";
echo "<input type='checkbox' name='delete_picture[]' value='".$row['img_name']."'>";
}
mysql_close($con);
?>
<input type='submit'>
</form>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@ss1289Mar 12.2008 — [code=php]$picture = $POST_[delete_picture];

foreach($picture as $name) {
mysql_query("DELETE FROM delete WHERE img_name = $name");
}[/code]


This might work.
Copy linkTweet thisAlerts:
@roondogauthorMar 12.2008 — Not sure whats happening. I've added
[code=php]
echo $name."<br />";
[/code]

which shows the image names but it's not deleting. I'll have to do more investigating
Copy linkTweet thisAlerts:
@roondogauthorMar 12.2008 — got it working just a little syntax error.
×

Success!

Help @roondog spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...