Demonic Posted February 6, 2007 Share Posted February 6, 2007 $erm = mysql_query("SELECT * FROM logs"); $ID = mysql_num_rows($erm); if(!isset($_POST['s'])){ echo ("<form method='post'>"); while($ermz = mysql_fetch_array($erm)){ echo ("<input type='checkbox' name='$ermz[id]' />$ermz[dee]<br />"); } echo ("<input type='submit' name='s' value='delete' /></form>"); }else{ for($i=1;$i<=$ID;$i++){ if(isset($_POST[$i])){ mysql_query("DELETE FROM logs WHERE id = '$i' ") or die("ERROR"); echo ("done"); } } } Alright when i have 5 rows in the DB and I use the script above it deletes 4 inputs and keeps the last one. Is there something im doing wrong where It doesn't delete all inputs. Link to comment https://forums.phpfreaks.com/topic/37251-some-quick-help-dealing-with-sqlinputs/ Share on other sites More sharing options...
genericnumber1 Posted February 6, 2007 Share Posted February 6, 2007 I'm not sure what you mean but give this a try... <?php $erm = mysql_query("SELECT * FROM logs"); if(!isset($_POST['s'])){ echo ("<form method='post'>"); while($ermz = mysql_fetch_array($erm)){ echo ("<input type='checkbox' name='delete[]' value='$ermz[id]' />$ermz[dee]<br />"); } echo ("<input type='submit' name='s' value='delete' /></form>"); }else{ for($i = 0; $i < count($_POST['delete']); ++$i) { mysql_query("DELETE FROM logs WHERE id = '{$_POST['delete'][$i]}' ") or die("ERROR"); } echo ("done"); } ?> btw.. PLEASE PLEASE PLEASE PLEASE INVEST IN VARIABLE NAMES THAT MEAN SOMETHING, I didn't correct it for you, but please, for the sake of everyone's sanity... thanks Also this script is vulnerable to sql injection, someone could create their own form and put in a malicious value for one of the delete entries, you might wanna look into that. Link to comment https://forums.phpfreaks.com/topic/37251-some-quick-help-dealing-with-sqlinputs/#findComment-177929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.