Part IV: Completing the modules for Generating Autonumber using PHP/MySQL

This tutorial is a continuation of our previous topic called “Part III: Generating Autonumber using PHP/MySQL”. At this time, we’re going to continue our lesson focusing on updating and deleting of autonumber. Let's create a new file and name it as “eautonum.php” and add the following code: This will perform if the “Edit Entry” on the autolist.php is clicked then it will get the “id” of specified autonumber and pass it into the URL during the POST method. Then when the “eatunum.php” is loaded, it will display the specific autonumber selected by the user into the textboxes provided.
  1. <?php
  2. /**
  3.  * Description: Edit Autonumber.
  4.  * Author: Joken E. Villanueva
  5.  * Date Created: May 24,2013
  6.  * Date Modified:June 6, 2013
  7.  */
  8. require_once("includes/initialize.php");
  9. include_layout_template_admin('admin_header.php');
  10. ?>
  11. <div id="menubar">
  12.  
  13. </script>
  14. <?php
  15. include("menus.php");
  16. ?>
  17. </div>
  18.  
  19.  
  20. <div id="module-name">Autonumber[Edit Entry]
  21. </div>
  22.  
  23. <?php
  24. $id = $_GET['id'];
  25. $mydb->setQuery("Select * from autonumber where auto_id=" . $id);
  26. $res = $mydb->loadSingleResult();
  27. /* $auto = new autonumbers();
  28. $cur = $auto->listOfautonumber();
  29. $rec = $user->singleUser($id); */
  30. ?>
  31.  
  32. <div id="content">
  33.  
  34. <form method="post" action="pAutonum.php">
  35.  
  36.  
  37. <table class="app_listing">
  38. <tr>
  39. <th > <div class="app_title" align="left">&nbsp;&nbsp;Autonumber Details</div></th>
  40. </tr>
  41. <tr class="form">
  42. <td class="form">
  43. <table class="app_form">
  44.  
  45. <tr>
  46. <td class="label" width="120">Autonumber Code :: </td>
  47. <td class="input">
  48. <input type="text" name="autocode" id="autocode" class="txtbox" value="<?php
  49. echo $res->autocode;
  50. ?>"/>
  51. </td>
  52. </tr>
  53. <tr>
  54. <td class="label">Autonumber Name :: </td>
  55. <td class="input">
  56. <input type="text" name="autoname" id="autoname" class="txtbox" value="<?php
  57. echo $res->autoname;
  58. ?>"/>
  59. </td>
  60. </tr>
  61. <tr>
  62. <td class="label">Append Character :: </td>
  63. <td class="input">
  64. <input type="text" name="appenchar" id="appenchar" class="txtbox" value="<?php
  65. echo $res->appenchar;
  66. ?>"/>
  67. </td>
  68. </tr>
  69. <tr>
  70. <td class="label">Autonumber Start :: </td>
  71. <td class="input">
  72. <input type="text" name="autostart" id="autostart" class="txtbox" value="<?php
  73. echo $res->autostart;
  74. ?>" />
  75. </td>
  76. </tr>
  77. <tr>
  78. <td class="label">Autonumber End :: </td>
  79. <td class="input">
  80. <input type="text" name="autoend" id="autoend" class="txtbox" value="<?php
  81. echo $res->autoend;
  82. ?>"/>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td class="label">Increment Value :: </td>
  87. <td class="input">
  88. <input type="text" name="incval" id="incval" class="txtbox" value="<?php
  89. echo $res->incval;
  90. ?>"/>
  91. <input type="hidden" name="datecreated" id="datecreated" class="txtbox" value="<?php
  92. echo date("Y-m-d");
  93. ?>"/>
  94. <input type="hidden" name="id" id="id" class="txtbox" value="<?php
  95. echo $id;
  96. ?>"/>
  97. </td>
  98. </tr>
  99. <tr>
  100. <td></td>
  101. <td>
  102. <input type="submit" name="submit" value="Save" class="app_button">
  103. </td>
  104. </tr>
  105.  
  106.  
  107. </table>
  108. </tr>
  109. </table>
  110. </form>
After this, we need to create another php file named “pAutonum.php”. And add the following code: This code will process the POST data submitted from “eautnum.php” to finally update the selected autonumber. Then if successfully updated the it will be redirected to “autolist.php” and then you see the newly updated autonumber.
  1. <?php
  2. require_once("includes/initialize.php");
  3. include_layout_template_public('header.php');
  4. ?>
  5.  
  6. <div id="menubar">
  7.  
  8. </div>
  9.  
  10. <div id="module-name">Edit User
  11. </div>
  12. <?php
  13.  
  14. $id = $_POST['id'];
  15. $autocode = $_POST['autocode'];
  16. $autoname = $_POST['autoname'];
  17. $appenchar = $_POST['appenchar'];
  18. $autostart = $_POST['autostart'];
  19. $autoend = $_POST['autoend'];
  20. $incval = $_POST['incval'];
  21. $datecreated = $_POST['datecreated'];
  22.  
  23. $auto = new autonumbers();
  24. $auto->auto_id = $id;
  25. $auto->autocode = $autocode;
  26. $auto->autoname = $autoname;
  27. $auto->appenchar = $appenchar;
  28. $auto->autostart = $autostart;
  29. $auto->autoend = $autoend;
  30. $auto->incval = $incval;
  31. $auto->datecreated = $datecreated;
  32. $auto->update($id);
  33.  
  34. ?>
  35. <script type="text/javascript">
  36. alert("Autonumber successfully updated!");
  37. window.location = "autolist.php";
  38. </script>
And lastly we will create create a another file named “delAutonum.php” and add the following code: This code will simply delete the selected autonumber by the user.
  1. <?php
  2. /**
  3.  * Description: Delete Autonumber.
  4.  * Author: Joken E. Villanueva
  5.  * Date Created: May 24,2013
  6.  * Date Modified:June 6, 2013
  7.  */
  8. require_once("includes/initialize.php");
  9. include_layout_template_public('header.php');
  10. ?>
  11.  
  12. <div id="menubar">
  13.  
  14. </div>
  15.  
  16.  
  17. <div id="module-name">Autonumber[Delete Entry]
  18. </div>
  19. <div id="content">
  20.  
  21. <?php
  22. $id = $_GET['id'];
  23. $rec = new autonumbers();
  24. $rec->delete($id);
  25. ?>
  26. <script type="text/javascript">
  27. alert("Autonumber has successfully deleted!");
  28. window.location = "autolist.php";
  29. </script>
And we’re done here folks, you can try now your application.

Add new comment