- <?php
- include("includes/db.php");
- //purchase.php
- if(isset($_REQUEST["lot"]))
- {
- // echo "<pre>";
- // print_r($_REQUEST);
- // die;
- $lot=$_REQUEST["lot"];
- $pdate=$_REQUEST["pdate"];
- $operator=$_REQUEST["operator"];
- $iname=$_REQUEST["iname"];
- $qty=$_REQUEST["qty"];
- $disc=$_REQUEST["disc"];
- $rate=$_REQUEST["rate"];
- $amnt=$_REQUEST["amnt"];
- $file=$_FILES["file"]["name"];
- $tmp_name=$_FILES["file"]["tmp_name"];
- $path="image/".$file;
- move_uploaded_file($tmp_name,$path);
- $comment=$_REQUEST["comment"];
- 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')");
- echo 1;
- die;
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>Page Title</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
- <script src="main.js"></script>
- </head>
- <body>
- <form method="post" id="frm1" enctype="multipart/form-data">
- Lot # :<Input type="text" name="lot" required><br><br>
- Purchase-Date:<Input type="date" name="pdate" required><br><br>
- 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
- </select><br><br>
- Item-Name:
- <?php $filename = 'includes/iname.txt';
- $eachlines = file($filename, FILE_IGNORE_NEW_LINES);//create an array
- echo '<select name="iname" id="value" required>';
- echo "<option value=''>Select Anyone</option>";
- foreach($eachlines as $lines){
- echo "<option value='{$lines}'>{$lines}</option>";
- }
- echo '</select>'; ?><br><br>
- Quantity:<Input type="text" name="qty"><br><br>
- Discount:<Input type="text" name="disc"><br><br>
- Rate:<Input type="text" name="rate"><br><br>
- Amount:<Input type="text" name="amnt"><br><br>
- File Upload
- <input type="file" name="file">
- <br><br>
- Comments:<Input type="text" name="comment" required><br><br>
- <Input type="submit" value="insert" name="submit">
- </form>
- </body>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <!-- load jquery via CDN -->
- <script>
- $(document).ready(function(){
- $('form').submit(function(event) {
- event.preventDefault();
- // get the form data
- // there are many ways to get this data using jQuery (you can use the class or id also)
- var formData = $(this).serializeArray()
- // process the form
- $.ajax({
- type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
- // url : '', // the url where we want to POST
- data : formData, // our data object
- dataType : 'json', // what type of data do we expect back from the server
- encode : true
- })
- // using the done promise callback
- .done(function(data) {
- // reset the form data
- document.getElementById('frm1').reset();
- // log data to the console so we can see
- alert('done');
- // here we will handle errors and validation messages
- });
- // stop the form from submitting the normal way and refreshing the page
- });
- })
- </script>
- </html>