Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here what you need to do is to handle the update and delete operations with the submit button name. What you need to do is to create two submit buttons with same name but different values. </p> <p>This is your form :</p> <pre><code>&lt;form action="" method="post"&gt; &lt;input name="action" type="submit" id="RetrieveList" value="RetrieveList" /&gt; &lt;input name="action" type="submit" id="DeletefromDB" value="DeleteFromDB" /&gt; &lt;input name="Clear" type="reset" id="Clear" value="Clear" /&gt; &lt;/form&gt; </code></pre> <p>I have given same name <code>action</code> for the two <code>submit</code> buttons. Once this form is submitted you can check the <code>$_POST['action']</code> in the server side.</p> <p>You can do it like:</p> <pre><code>if ($_POST['action'] == 'RetrieveList') { //retreive list functionality } elseif ($_POST['action'] == 'DeleteFromDB') { //delete from dB functionality. } </code></pre> <p><strong>UPDATE:</strong></p> <p>You need to change your form like this :</p> <pre><code>echo "&lt;form action='resultgenerator.php' method='post'&gt;"; echo '&lt;input name="action" type="submit" id="DeletefromDB" value="Delete from DB" /&gt;'; echo "&lt;table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'&gt; &lt;tr&gt; &lt;th align='center'&gt;&lt;input id=checkall name=checkall type=checkbox value='' /&gt;&lt;/th&gt; &lt;th align='center'&gt;Remedy Ticket No.&lt;/th&gt; &lt;th align='center'&gt;Phone/Incident No.&lt;/th&gt; &lt;th align='center'&gt;Category 2&lt;/th&gt; &lt;th align='center'&gt;Category 3&lt;/th&gt; &lt;th align='center'&gt;Status&lt;/th&gt; &lt;th align='center'&gt;Create Date&lt;/th&gt; &lt;th align='center'&gt;Severity&lt;/th&gt; &lt;th align='center'&gt;Ban Type&lt;/th&gt; &lt;th align='center'&gt;Resolved Date&lt;/th&gt; &lt;/tr&gt;"; while($info = mysql_fetch_array($myData)) { echo"&lt;tr&gt;"; echo "&lt;td align='center'&gt;" . "&lt;input type='checkbox' name='checkbox[]' value='add the id here which needs to be deleted'/&gt;&lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['ars_no'] . "&lt;input type=hidden name=ars_no value=" . $info['ars_no'] . " &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['phone_number'] . "&lt;input type=hidden name=phone_number value=" . $info['phone_number'] . " size='11' maxlength='11' /&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['category_1'] . "&lt;input type=hidden name=category_1 value=" . $info['category_1'] . "' /&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['category_2'] . "&lt;input type=hidden name=category_2 value=" . $info['category_2'] . "' /&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['status'] . "&lt;input type=hidden name=status value=" . $info['status'] . "' /&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['create_date'] . "&lt;input type=hidden name=create_date value=" . $info['create_date'] . "' /&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['trouble_type_priority'] . "&lt;input type=hidden name=trouble_type_priority value=" . $info['trouble_type_priority'] . " size='1' maxlength='1' /&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $info['ban_type'] . "&lt;input type=hidden name=ban_type value=" . $info['ban_type'] . " size='1' maxlength='1' /&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . "&lt;input type=text name=resolved_date value=" . $info['resolved_date'] . " size='8' maxlength='8' /&gt; &lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; echo "&lt;/form&gt;"; </code></pre> <p>Now in your <strong>resultgenerator.php</strong> file you can check :</p> <pre><code>if ($_POST['action'] == 'DeleteFromDB') { $ids_to_be_deleted = isset($_POST['checkbox']) ? $_POST['checkbox'] : array(); //$ids_to_be_deleted will contain all the checked id's from the other page. You can get all those values in the array. Handle the remaining operation for delete here. } </code></pre> <p><strong>NEW UPDATE :</strong></p> <p>So if you are using jQuery to submit your form, then it would be better to change the form submit binding to click function on the button. You can change your form to :</p> <pre><code> &lt;link href="jquery-ui-1.10.2.custom/css/dark-hive/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript" src="jquery-1.9.1.min.js" &gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.js" &gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js" &gt;&lt;/script&gt; &lt;link rel="stylesheet" href="style.css" /&gt; &lt;script type="text/javascript" src="SMP1_deletefromDB.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("#RetrieveList").on('click',function() { var xid = $('#XiD').val(); var date = $('#Date').val(); $.post('resultgenerator.php',{xid:xid, date:date}, function(data){ $("#results").html(data); }); return false; }); $("#DeletefromDB").on('click',function() { //get xid for delete like you do above. create a page delete.php or something and make an ajax call to some page to delete data return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body class="oneColFixCtrHdr"&gt; &lt;div id="container" style="width:auto"&gt; &lt;div id="header" style="background-color:#7BD12E"&gt; &lt;h1 align="left" style="color:#FFF; font-family: Arial, Helvetica, sans-serif;"&gt;PIS Ticket Tracking System&lt;/h1&gt; &lt;!-- end #header --&gt;&lt;/div&gt; &lt;div id="mainContent"&gt; &lt;h1 style="font-size:9"&gt;&lt;/h1&gt; &lt;form id="form1" name="form1" method="post" action=""&gt; &lt;p&gt; &lt;label for="Back"&gt;&lt;/label&gt; &lt;input type="button" name="Back" id="Back" value="Back To Main" href="#" onclick="return backAway();" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;form id="form2" name="form2" method="post" action=""&gt; &lt;table width="741" border="0" align="center"&gt; &lt;tr&gt; &lt;th colspan="9" align="center" style="font-size:12px" scope="col"&gt;Xid, Name:&lt;span&gt; &lt;select name="XiD" id="XiD"&gt; &lt;option value="AAA"&gt;AAA&lt;/option&gt; &lt;option value="BBB"&gt;BBB&lt;/option&gt; &lt;option value="CCC"&gt;CCC&lt;/option&gt; &lt;option value="DDD"&gt;DDD&lt;/option&gt; &lt;option value="EEE"&gt;EEE&lt;/option&gt; &lt;option value="FFF"&gt;FFF&lt;/option&gt; &lt;option value="" selected="selected"&gt;&lt;/option&gt; &lt;/select&gt; &lt;/span&gt;&lt;span style="font-size:12px"&gt; &lt;label for="date"&gt;Date:&lt;/label&gt; &lt;input type="text" name="Date" id="Date" /&gt; &lt;/span&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th colspan="9" scope="col"&gt;&amp;nbsp;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th colspan="9" scope="col"&gt; &lt;div align="center"&gt; &lt;input name="action" type="button" id="RetrieveList" value="RetrieveList" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;input name="action" type="button" id="DeletefromDB" value="DeleteFromDB" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;input name="Clear" type="reset" id="Clear" value="Clear" /&gt; &lt;/div&gt; &lt;label for="Clear"&gt;&lt;/label&gt; &lt;div align="center"&gt;&lt;/div&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/form&gt; &lt;div id="results"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here What I have done is changed the binding event on form submit and binded on click event of input type buttons. I changed type submit to button.</p> <p>Now you can check on the click event of each buttons and handle the operations.</p> <p><strong>UPDATE:</strong></p> <p>Assuming that you have the retrieved list in your results div. When the user check the checkboxes and click the delete button you can handle it using this script:</p> <pre><code>$("#DeletefromDB").on('click',function() { //get all the checked values from checkboxes var ids = $('input[name=checkbox]:checked').map(function () { return this.value; }).get(); if (ids.length === 0) return false; //show some error message //post to delete.php file. In delete.php you can get the id's in $_POST['id'] as multidimensional array. You can handle the delete operation based on that $.post('delete.php',{id : ids}, function(data){ //handle the message based on success or error }); return false; }); </code></pre> <p><strong>UPDATE :</strong></p> <p>This can be your <strong>delete.php</strong> file</p> <pre><code>$ids = isset($_POST['id']) ? $_POST['id'] : ''; if (!empty($ids)) { //implode the id's separated by commaas $ids_to_be_deleted = implode(',', $ids); $query = "DELETE FROM your_table WHERE field_to_be_checked IN ($ids_to_be_deleted)"; //now run your query using mysql_query } </code></pre> <p><strong>NB:</strong> : mysql* functions are deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the <a href="http://www.php.net/manual/en/book.mysqli.php" rel="nofollow"><strong>MySQLi</strong></a> or <a href="http://www.php.net/manual/en/ref.pdo-mysql.php" rel="nofollow"><strong>PDO_MySQL</strong></a> extension should be used</p> <p>Hope this helps you :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload