From ali, 6 Years ago, written in Plain Text.
Embed
  1. <?php
  2.  
  3. include("includes/db.php");
  4. //purchase.php
  5. if(isset($_REQUEST["lot"]))
  6. {
  7.         // echo "<pre>";
  8.         // print_r($_REQUEST);
  9.         // die;
  10.         $lot=$_REQUEST["lot"];
  11.         $pdate=$_REQUEST["pdate"];
  12.         $operator=$_REQUEST["operator"];
  13.         $iname=$_REQUEST["iname"];
  14.         $qty=$_REQUEST["qty"];
  15.         $disc=$_REQUEST["disc"];
  16.         $rate=$_REQUEST["rate"];
  17.         $amnt=$_REQUEST["amnt"];
  18.         $file=$_FILES["file"]["name"];
  19.         $tmp_name=$_FILES["file"]["tmp_name"];
  20.         $path="image/".$file;
  21.         move_uploaded_file($tmp_name,$path);
  22.         $comment=$_REQUEST["comment"];
  23.         mysql_query("insert into purchased(lot,pdate,operator,item_name,quantity,discount,rate,amount,file,comment)values('$lot','$pdate','$operator','$iname','$qty','$disc','$rate','$amnt','$file','$comment')");
  24.         echo 1;
  25.         die;
  26. }
  27. ?>
  28.  
  29. <!DOCTYPE html>
  30. <html>
  31. <head>
  32. <meta charset="utf-8" />
  33. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  34. <title>Page Title</title>
  35. <meta name="viewport" content="width=device-width, initial-scale=1">
  36. <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
  37. <script src="main.js"></script>
  38. </head>
  39. <body>
  40.  
  41.  
  42. <form method="post" id="frm1" enctype="multipart/form-data">
  43. Lot # :<Input type="text" name="lot" required><br><br>
  44. Purchase-Date:<Input type="date" name="pdate" required><br><br>
  45. Operator :<Input type="radio"name="operator"value="Zong" required>Zong<Input type="radio"name="operator"value="Telenor" required>Telenor<Input type="radio"name="operator"value="Jazz" required>Jazz
  46. </select><br><br>
  47. Item-Name:
  48. <?php $filename = 'includes/iname.txt';
  49. $eachlines = file($filename, FILE_IGNORE_NEW_LINES);//create an array
  50. echo '<select name="iname" id="value" required>';
  51. echo "<option value=''>Select Anyone</option>";
  52. foreach($eachlines as $lines){
  53. echo "<option value='{$lines}'>{$lines}</option>";
  54. }
  55. echo '</select>'; ?><br><br>
  56. Quantity:<Input type="text" name="qty"><br><br>
  57. Discount:<Input type="text" name="disc"><br><br>
  58. Rate:<Input type="text" name="rate"><br><br>
  59. Amount:<Input type="text" name="amnt"><br><br>
  60. File Upload
  61. <input type="file" name="file">
  62. <br><br>
  63. Comments:<Input type="text" name="comment" required><br><br>
  64. <Input type="submit" value="insert" name="submit">
  65.  
  66. </form>
  67.  
  68. </body>
  69.  
  70. <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <!-- load jquery via CDN -->
  71. <script>
  72. $(document).ready(function(){
  73. $('form').submit(function(event) {
  74. event.preventDefault();
  75.  
  76. // get the form data
  77. // there are many ways to get this data using jQuery (you can use the class or id also)
  78. var formData = $(this).serializeArray()
  79.  
  80. // process the form
  81. $.ajax({
  82. type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
  83. // url : '', // the url where we want to POST
  84. data : formData, // our data object
  85. dataType : 'json', // what type of data do we expect back from the server
  86. encode : true
  87. })
  88. // using the done promise callback
  89. .done(function(data) {
  90. // reset the form data
  91.  
  92. document.getElementById('frm1').reset();
  93.  
  94. // log data to the console so we can see
  95. alert('done');
  96.  
  97. // here we will handle errors and validation messages
  98. });
  99.  
  100. // stop the form from submitting the normal way and refreshing the page
  101. });
  102.  
  103.  
  104. })
  105. </script>
  106. </html>