Posted By

Ankur on 03/27/14


Tagged

phpmysql


Versions (?)

PHP Form handling


 / Published in: PHP
 

URL: myoop

Making it OOP way.

  1. <?php include("includes/connection.php");?>
  2. <?php
  3. if(!(isset($_SESSION['adminname'])))
  4. {
  5. header("Location:front/login.php");
  6. exit();
  7. }
  8. ?>
  9. <?php
  10. $offset=(5*60*60)+(30*60);
  11. $format="Y-m-d H:i:s";
  12. $time=gmdate($format,(time()+$offset));
  13. ?>
  14. <?php $i=rand();?>
  15. <?php
  16. if(isset($_POST['add']))
  17. {
  18. $code=$i;
  19. $bname=$con->real_escape_string($_POST['bname']); //OOP Used only here!
  20. $incharge=$con->real_escape_string($_POST['incharge']);
  21. $contact=$con->real_escape_string($_POST['contact']);
  22. $email=$con->real_escape_string($_POST['email']);
  23. $address=$con->real_escape_string($_POST['address']);
  24. $lastlogged=0;
  25.  
  26. if(empty($incharge) || empty($bname) || empty($email) || empty($address))
  27. {
  28. echo "<script type='text/javascript'>alert('Please fill the required fields!');</script>";
  29. }
  30. else
  31. {
  32. $q="insert into branch (code,bname,incharge,lastlogged,createdon,contactno,email,address)
  33. values('$i','$bname','$incharge','$lastlogged','$time','$contact','$email','$address')";
  34. $res=$con->query($q);
  35. if($res)
  36. {
  37. echo "<script type='text/javascript'>alert('Branch Successfully Added!');</script>";
  38. }
  39. else
  40. {
  41. echo "<script type='text/javascript'>alert('Something went wrong,Try Again!');</script>";
  42. }
  43. }
  44. }
  45. else
  46. {
  47. $bname="";
  48. $incharge="";
  49. $lastlogged="";
  50. $contact="";
  51. $email="";
  52. $address="";
  53. }
  54. ?>
  55. <html>
  56. <head>
  57. <link rel="stylesheet" type="text/css" href="css/style.css"/>
  58. </head>
  59. <body>
  60. <center>
  61. <p class="bheading">Add New Branch</p>
  62. <form action="addb.php" method="post">
  63. <table cellpadding="5" cellspacing="5">
  64. <tr>
  65. <td>Code:</td><td><?php echo $i;?></td>
  66. </tr>
  67. <tr>
  68. <td>Branch Name:</td><td><input type="text" name="bname" size="38"></td>
  69. </tr>
  70. <tr>
  71. <td>Incharge:</td><td><input type="text" name="incharge" size="38"></td>
  72. </tr>
  73. <tr>
  74. <td>Contact No:</td><td><input type="number" name="contact" style="width:100%"></td>
  75. </tr>
  76. <tr>
  77. <td>Email:</td><td><input type="email" name="email" size="38"></td>
  78. </tr>
  79. <tr>
  80. <td>Address:</td><td><input type="text" name="address" size="38"></td>
  81. </tr>
  82. </table></br></br>
  83. <input type="Submit" name="add" value="Add Branch">
  84. </form>
  85. </center>
  86. </body>
  87. </html>

Report this snippet  

You need to login to post a comment.