Pradeep_Chinna Posted October 3, 2013 Share Posted October 3, 2013 Can anyone help me out my problem... When i click on delete link, it should confirm through confirm box and delete checked multiple rows... This is my code... $sql = " SELECT * FROM budget where NAME=\"$name\"; $rs = mysql_query($sql,$con); if(mysql_num_rows($rs) == 0) { echo("<p class=\"no\">Sorry, NO Records Found..!</p> <p class=\"no\">Pleasd try with another Name.</p> "); } else { echo "<table id='main-table' cellspacing='0' cellpadding='0' class=\"table1\"> <tr class=\"rowh\"> <td>Date</td> <td>Name</td> <td colspan=\"2\"> ACTIONS </td> </tr>"; while ($row=mysql_fetch_array($rs)) { echo ("<tr><td class=\"rowr\">$row[DATE]</td>"); echo ("<td class=\"rowr\">$row[NAME]</td>"); echo ("<td ><a class=\"rowrl\" href==\"edit_form.php?number=$row[iD]\"> Edit </a></td>"); echo ("<td ><input name=\"check\" type=\"checkbox\" /></td></tr>"); } echo "<tr class=\"delete\" align=\"right\" > <td colspan=\"7\" align=\"right\"><a class=\"rowrl\" href=\"delete.php?number=$row[iD]\" onclick=\"return confirm('Do you really want to DELETE ?');\"> Delete </a></td> </tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/ Share on other sites More sharing options...
Ch0cu3r Posted October 3, 2013 Share Posted October 3, 2013 Your code as-s wont submit the checked values as <input />'s belong to forms not links. What you need to do is surround the table with a form that submits to delete.php. Then set the onsubmit attribute to the confirm dialog box which pops up when the submit button is pressed. <form action="delete.php" method="get" onsubmit="return confirm('Do you really want to DELETE ?');")> ... table code here ... <input type="submit" name="submit" value="Delete" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452467 Share on other sites More sharing options...
Pradeep_Chinna Posted October 3, 2013 Author Share Posted October 3, 2013 Due to device problm i was unable to post my exact doubt.., My actual questn is, Deleting multiple rows using checkboxs and anchor tag Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452469 Share on other sites More sharing options...
Ch0cu3r Posted October 3, 2013 Share Posted October 3, 2013 (edited) In order for the values of the selected checkboxes to be received in delete.php you need to have a form. Once you have the form implemented you can submit the form using the anchor tag if you wish. You'll set up the checkboxes with this echo ("<td ><input name=\"del[]\" value=\"{$row['ID']}\" type=\"checkbox\" /></td></tr>"); Now in delete.php how you'd proceses the selected checkboxes would be like this if(is_array($_GET['del'])) { $ids = array_map('intval', $_GET['del']); $ids = implode(',', $ids); $query = mysql_query("DELETE FROM your_table WHERE your_id_field IN ($ids)"); } Edited October 3, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452473 Share on other sites More sharing options...
jazzman1 Posted October 3, 2013 Share Posted October 3, 2013 @Pradeep_Chinna, next time try to give a meaningful topic title to your problematic thread, not just "del"!Do you know that this text editor supports BBcode tags itself? Use them like @Ch0cu3r, please! Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452481 Share on other sites More sharing options...
Pradeep_Chinna Posted October 4, 2013 Author Share Posted October 4, 2013 @jazzman1 : yes i knew it aint a meaningful title...due to my device problem i was unable to write complete title of my post. No problm it wont happn again...:-) Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452528 Share on other sites More sharing options...
Ch0cu3r Posted October 4, 2013 Share Posted October 4, 2013 @jazzman1 : yes i knew it aint a meaningful title...due to my device problem i was unable to write complete title of my post. No problm it wont happn again...:-) Did my reply help? http://forums.phpfreaks.com/topic/282688-del/?do=findComment&comment=1452473 Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452529 Share on other sites More sharing options...
Pradeep_Chinna Posted October 4, 2013 Author Share Posted October 4, 2013 @ch0cu3r: not done ch0cu3r.... i've closed if loop before sql query stmt. Is that true ? Its going to my delete.php and executing but showing updated records: -1 ..???? My code After query if(isset($sql)) {echo"deletd sucfly"; printf("updated records:", mysql_affected_rows()); } Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452592 Share on other sites More sharing options...
Ch0cu3r Posted October 4, 2013 Share Posted October 4, 2013 (edited) @igen121 how is that helping? @Pradeep_ChinnaPost delete.php here. How are you implanting my code example? if mysql_affected_rows() returned -1 then the SQL query is failing, probably due to an error. You can see what the error is using mysql_error When posting code, please paste code into the code tags by clicking the <> button. Edited October 4, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452594 Share on other sites More sharing options...
Pradeep_Chinna Posted October 5, 2013 Author Share Posted October 5, 2013 Sorry for late :-P Am using mobile not computer. There is no other bb or color opts in mobile version. @ch0cr3: i've deletd unnecessary code. this is my delete.php: <body background="bg_tile.jpg"> <div class="content"> <div class="header"> <div class="uname"> <div class="welcome"> <?php if(isset($_SESSION['username'])) { echo "Welcome ".$_SESSION['username']."<br/>"."<br/>";?> <?php echo "<br/>"; } ?> </div> <div class="logout"> <a class="logout2" href="index.php">Logout</a> </div> <span id="date_time"></span> </div> <div class="separator"></div> </div> <div class="right-div"> <?php $no=$_GET['number']; $checkbox= $_POST['checkbox']; // Connect to the database $con = mysql_connect("localhost","admin",""); // Make sure we connected succesfully if(! $con) { die('Connection Failed'.mysql_error()); } // Select the database to use mysql_select_db("test",$con); if(is_array($_GET['del'])) { $ids = array_map('intval', $_GET['del']); $ids = implode(',',$ids); } $order = " DELETE FROM budget WHERE ID IN($ids) "; $result=mysql_query($order, $con); if(isset($result)) { print "Deleted successfully "; echo "<br/>"; printf ("Updated records: %d\n", mysql_affected_rows()); echo "<br/>"."<br/>"; } ?> </div> <div class="footer"> <div class="footer_inside" ><p class="text">©2013 All Rightst5a </p> </div> </div> </div> </body> Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452663 Share on other sites More sharing options...
jcbones Posted October 5, 2013 Share Posted October 5, 2013 [ code ] and [ / code ] should still work. Quote Link to comment https://forums.phpfreaks.com/topic/282688-del/#findComment-1452664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.