Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想继续存储和显示我从mysql获得的结果_Javascript_Php_Jquery_Mysql_Arrays - Fatal编程技术网

Javascript 我想继续存储和显示我从mysql获得的结果

Javascript 我想继续存储和显示我从mysql获得的结果,javascript,php,jquery,mysql,arrays,Javascript,Php,Jquery,Mysql,Arrays,我不是php方面的专家,只是一个新手,所以不知道该怎么做。我想做的是继续保存从文本框中得到的结果,并继续在我的页面上显示它。文本框的图片已附加。我想继续存储我从表中得到的新结果,并继续显示旧结果。我希望我想做的事情很清楚。我的代码有三个文件。主文件products.php有以下代码 <!DOCTYPE html> <html> <head> <title>Products</title> <p> Scan t

我不是php方面的专家,只是一个新手,所以不知道该怎么做。我想做的是继续保存从文本框中得到的结果,并继续在我的页面上显示它。文本框的图片已附加。我想继续存储我从表中得到的新结果,并继续显示旧结果。我希望我想做的事情很清楚。我的代码有三个文件。主文件products.php有以下代码

<!DOCTYPE html>
<html>
<head>
    <title>Products</title>
    <p> Scan the Barcode of the Product </p>
    <link href="mystyle.css" rel="stylesheet">
</head>
<body>

        <input type="text" name="enter" required id="item" style="text-align:centre" placeholder=" Barcode ID" autofocus />

        <div id="item-data"></div>

        <script src="js/jquery-2.2.0.min.js"></script> <!--jquery link-->
        <script src="js/global.js"></script> <!--linking event file-->

</body>
</html>
<?php

require '../db/connect.php';

$id= $_POST['id']; // your post variable
$sql = "SELECT BarcodeID, shirts, price FROM clothes WHERE  BarcodeID=".mysqli_real_escape_string($con,$id);

$result = mysqli_query($con,$sql) or die(mysqli_error($con));

if(mysqli_num_rows($result)>0)
{
    while($row = $result->fetch_assoc())
    {
        echo " " . $row["BarcodeID"]. " shirt color:  " . $row["shirts"]. "  price: " . $row["price"];
    }
}
else
{
        echo "ID not found, Please Scan again";
}
mysqli_close($con);

?>
而global.js的代码是

$(function(){

//press enter on text area..

$('#item').keypress(function (event) {
var key = event.which;
if(key == 13)  // the enter key code
{

var item = $('input#item').val();    // retreiving the value from the item
    if ($.trim(item) != ''){            //send this to php file but if its     empty or spaces(trim) are there dont send it//
        $.post('ajax/name.php',{id:item}, function(data){   //using post method sending to the father(name.php), sending the data through the file item
            $('div#item-data').append(""+data+"</br>"); // grabing the data and displaying it

        });

    }

$('#item').val('');
 }
 });

});
第三个文件my name.php包含以下代码

<!DOCTYPE html>
<html>
<head>
    <title>Products</title>
    <p> Scan the Barcode of the Product </p>
    <link href="mystyle.css" rel="stylesheet">
</head>
<body>

        <input type="text" name="enter" required id="item" style="text-align:centre" placeholder=" Barcode ID" autofocus />

        <div id="item-data"></div>

        <script src="js/jquery-2.2.0.min.js"></script> <!--jquery link-->
        <script src="js/global.js"></script> <!--linking event file-->

</body>
</html>
<?php

require '../db/connect.php';

$id= $_POST['id']; // your post variable
$sql = "SELECT BarcodeID, shirts, price FROM clothes WHERE  BarcodeID=".mysqli_real_escape_string($con,$id);

$result = mysqli_query($con,$sql) or die(mysqli_error($con));

if(mysqli_num_rows($result)>0)
{
    while($row = $result->fetch_assoc())
    {
        echo " " . $row["BarcodeID"]. " shirt color:  " . $row["shirts"]. "  price: " . $row["price"];
    }
}
else
{
        echo "ID not found, Please Scan again";
}
mysqli_close($con);

?>

通过在javascript中使用append函数解决了这个问题。检查global.js文件。

请使用准备好的语句,这里:$sql=选择BarcodeID,衬衫,衣服价格,其中BarcodeID=.$id;打开一个SQL注入漏洞。我不太确定如何做。google准备的语句phpI编辑了my name.php以防止SQL注入。我希望现在一切都好。是的,太好了: