Sunday 15 September 2013

php - Delete form with checkbox doesn't work -



php - Delete form with checkbox doesn't work -

i'm trying checkbox form delete entries database/ftp server can't delete button delete something. because i'm missing out on error reporting keeps telling variable delete isn't determined can't find why says that.

this code,

class="snippet-code-html lang-html prettyprint-override"><?php error_reporting(e_all); ini_set('display_errors', 1); // our database connector require("includes/conn.php"); ?> <?php $sql="select * people order id"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#cccccc"> <tr> <td bgcolor="#ffffff">&nbsp;</td> <td colspan="4" bgcolor="#ffffff"><strong>selecteer welke auto('s) verkocht zijn</strong> </td> </tr> <tr> <td align="center" bgcolor="#ffffff">#</td> <td align="center" bgcolor="#ffffff"><strong>foto</strong></td> <td align="center" bgcolor="#ffffff"><strong>merkt/type</strong></td> <td align="center" bgcolor="#ffffff"><strong>beschrijving</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ echo "<div class=\"picture\">"; echo "<p>"; ?> <tr> <td align="center" bgcolor="#ffffff"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#ffffff"><? echo "<img src=\"content/uploads/" . $rows['filename'] . "\" alt=\"\" height=\"125\" width=\"200\" /><br />" . "<br />"; ?></td> <td bgcolor="#ffffff"><? echo $rows['fname']; ?></td> <td bgcolor="#ffffff"><? echo $rows['lname']; ?></td> </tr> <?php echo "</p>"; echo "</div>"; } ?> <tr> <td colspan="5" align="center" bgcolor="#ffffff"><input name="delete" type="submit" id="delete" value="delete"></td> </tr> <?php // check if delete button active, start if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "delete people id='$del_id'"; $result = mysql_query($sql); } // if successful redirect delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;url=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table>

another problem i'm having code want delete image ftp too, not file name entry in database.

p.s. know mysql beingness deprecated, i'm going edit after have script working want too. didn't have time yet take @ pdo , mysqli.

try this:

<?php if(isset($_post['delete'])){ // check delete button clicked foreach($_post['checkbox'] $del_id){ // loop checked items , delete $sql = "delete people id='$del_id'"; $result = mysql_query($sql); } } ?>

and ever logic have written delete move top of page before html code desired output.

php mysql forms checkbox

No comments:

Post a Comment