just me and php Posted November 2, 2006 Share Posted November 2, 2006 This displays all tables and fields nicely , if i check box and click the delete button it acts like everything is ok no errors and it refreshes back to its own page but nothing was deleted , can someone see why??Thanks :)[code]<?phprequire "configdelete.php";$sql="SELECT * FROM $tbl_name";$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"> </td><td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td></tr><tr><td align="center" bgcolor="#FFFFFF">#</td><td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td></tr><?phpwhile($rows=mysql_fetch_array($result)){?><tr><td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td><td bgcolor="#FFFFFF"><? echo $rows['recno']; ?></td></tr><?php}?><tr><td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td></tr><?// Check if delete button active, start this if($delete){for($i=0;$i<$count;$i++){$del_id = $checkbox[$i];$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";$result = mysql_query($sql);}// if successful redirect to delete_multiple.php if($result){echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";}}mysql_close();?></table></form></td></tr></table>[/code] Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/ Share on other sites More sharing options...
trq Posted November 2, 2006 Share Posted November 2, 2006 Where do you define $delete? You dont. You need to use the $_POST array. eg;[code=php:0]if ($_POST['delete']){[/code] Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118451 Share on other sites More sharing options...
just me and php Posted November 2, 2006 Author Share Posted November 2, 2006 Thanks for the quick Replywould i replace if($delete){With if ($_POST['delete']){?i just try that and i have the same results Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118457 Share on other sites More sharing options...
trq Posted November 2, 2006 Share Posted November 2, 2006 Yes. Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118464 Share on other sites More sharing options...
just me and php Posted November 2, 2006 Author Share Posted November 2, 2006 Hmm that didnt change anything , had same results but?should this [code]$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";[/code]Be this? [code] $sql = "DELETE recno, Username, track, HL_F, HL_MS, online, disp, PCLabel, PCValid, PC, date, display, hacked, MP, osFROM $tbl_name WHERE id='$del_id'";[/code]With the replace if($delete){With if ($_POST['delete']){ Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118488 Share on other sites More sharing options...
trq Posted November 2, 2006 Share Posted November 2, 2006 I think your logic is a little off. Should be something like...[code=php:0]if($_POST['delete']){ foreach($_POST['checkbox'] as $del_id){ $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; if (mysql_query($sql)) echo "Deleted $del_id"; } }}[/code] Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118491 Share on other sites More sharing options...
just me and php Posted November 2, 2006 Author Share Posted November 2, 2006 Would or can MYSQL be blocking me? Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118495 Share on other sites More sharing options...
just me and php Posted November 3, 2006 Author Share Posted November 3, 2006 can anyone give me an idea where im going wrong here? Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118903 Share on other sites More sharing options...
btherl Posted November 3, 2006 Share Posted November 3, 2006 Does it say "Deleted X", where X is a $del_id?If not, there are 3 ways it could fail. Either the query failed, $_POST['checkbox'] is empty or $_POST['delete'] is not true.Try this:[code]var_dump($_POST['delete']);var_dump($_POST['checkbox']);[/code]just before the if ($_POST['delete']);Also, add an "else" case to the check for query failure:[code]... } else { echo "Query $sql failed! Error was " . mysql_error();}[/code] Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118938 Share on other sites More sharing options...
just me and php Posted November 3, 2006 Author Share Posted November 3, 2006 Thanks Guys Found the Problem I Wasnt Defining id So Code Couldnt Find It.Thanks For The Help , And Thanks For This Forum ;) Link to comment https://forums.phpfreaks.com/topic/25937-solvedwhy-wont-this-work-help-please/#findComment-118989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.