简体   繁体   中英

Input-Scan Barcode PHP

i have this form

form_insert.php

<form action="stock_insert.php" method="get">
        <input type="text" name="barcode" placeholder="Εισαγωγή BarCode"> <br>
        <input type="text" name="name" placeholder="Όνομα"> <br>
        <input type="text" name="size" placeholder="Μέγεθος"> <br>
        <input type="text" name="style" placeholder="Στυλ"> <br>
        <input type="text" name="color" placeholder="Χρώμα">  <br>
        <input type="text" name="mark" placeholder="Μάρκα"> <br>
        <input type="text" name="value" placeholder="Ποσότητα">  <br>
        <input type="text" name="price" placeholder="Τιμή"> <br>
        <select name="kind">
            <option >Σταθερά</option>
            <option >Φθινόπωρο</option>
            <option >Χειμώνας</option>
            <option >Άνοιξη</option>
            <option >Καλοκαίρι</option>
        </select> <br>
        <input type="submit" name="Αποθήκευση"  placeholder="Αποθήκευση">
</form>

I want to insert in my database the inputs.

stock_insert.php

<?php
include_once  'database_connection.php';

$barcode = $_GET['barcode'];
$name = $_GET['name'];
$size = $_GET['size'];
$style = $_GET['style'];
$color = $_GET['color'];
$mark = $_GET['mark'];
$kind = $_GET['kind'];
$value = $_GET['value'];
$price =$_GET['price'];

$sql = "INSERT INTO `stock`(`barcode`, `name`, `size`,  `style`, `color`, `mark`, `kind`, `value` , price) VALUES ('$barcode','$name','$size','$style','$color','$mark' ,'$kind','$value', $price);";

mysqli_query($conn, $sql);

header('Location: form_insert.php?signup=success');

But every time , that i'm scanning my Barcode into the input , it automatically refreshes and disappears

What should i do to avoid it ?

Thanks for the comments guys. Here is the solution.

AJAX CODE

<script>
        $(document).ready(function(){

            $("#submit").click(function(){
                var barcode =  $("#barcode").val();
                var name = $("#name").val();
                var size = $("#size").val();
                var style  = $("#style").val();
                var color = $("#color").val();
                var mark = $("#mark").val();
                var value  = $("#value").val();
                var price = $("#price").val();
                var kind = $("#kind").val();
                $.post("stock_insert.php", 
                {
                    barcode: barcode ,
                    name: name ,
                    size: size ,
                    style: style ,
                    color: color ,
                    mark: mark ,
                    value: value ,
                    price: price ,
                    kind: kind 
                },function(data,status){
                    alert(status);

                });


           });
        });
    </script>

Inputs

<input type="text" id="barcode" name="barcode" placeholder="Εισαγωγή BarCode"> <br>
        <input type="text" id="name" name="name" placeholder="Όνομα"> <br>
        <input type="text" id="size" name="size" placeholder="Μέγεθος"> <br>
        <input type="text" id="style" name="style" placeholder="Στυλ"> <br>
        <input type="text" id="color" name="color" placeholder="Χρώμα">  <br>
        <input type="text" id="mark" name="mark" placeholder="Μάρκα"> <br>
        <input type="text" id="value" name="value" placeholder="Ποσότητα">  <br>
        <input type="text" id="price" name="price" placeholder="Τιμή"> <br>
        <select id="kind" name="kind">
            <option >Σταθερά</option>
            <option >Φθινόπωρο</option>
            <option >Χειμώνας</option>
            <option >Άνοιξη</option>
            <option >Καλοκαίρι</option>
        </select> <br>
        <input type="submit" id="submit" name="Αποθήκευση"  placeholder="Αποθήκευση">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM