我的表单不会在输入文本中提交信息

时间:2016-07-06 09:46:25

标签: php jquery forms

我正在做一张桌子,用户可以在其中介绍他想要购买的产品数量,并按下提交按钮提交。我使用SQL查询(SELECT)来设置表的内容,设置输入(文本)的名称,如下面的代码所示。我的问题是,表单可能没有提交任何内容,因为如果使用isset()检查变量$ _REQUEST,则返回FALSE。有人可以帮帮我吗?谢谢!

$con=mysqli_connect("localhost","uPower","","info"); 
    if (mysqli_connect_errno()) 
      printf("<p>Error!!: %s<p>\n", mysqli_connect_error());
    else{
        $query = "SELECT * FROM product"; 
        $result = mysqli_query ($con, $query);  
echo "<form name=\"buy\" action=\"confirm.php\" method=\"POST\" onSubmit=\"return checkInputQty(qty.value) \">";
        echo"<table>";
        echo"<tr><th>Product name</th><th>Price</th><th>Available</th><th>Qty</th></tr>";
         while ($row = mysqli_fetch_assoc($result)){
            $pid = $row["pid"];
            $name = $row["name"];
            $qty = $row["qty"];
            $price = ($row['price'])/100;
            echo"<tr><th>$name</th><th>".number_format($price,2,',', '')." &#8364</th><th>$qty</th><th><input type=\"text\" id=".$pid." name=".$name."></th></tr>";
        }
        echo"</table>";
echo "<p><input type=\"submit\" value=\"BUY\" class=\"button\" ><input type=\"button\" onclick=\"clearText()\" value=\"DELETE\" class=\"button\"></p>"; 
echo "</form>";
        mysqli_free_result($result);
        mysqli_close($con);

有confirm.php的一部分。这是我从页面正文中调用的头部功能。它总结了用户选择购买的内容。 if(isset($ _ REQUEST))的控件为false,因此页面为空白....

<?php 

function checkInputQty(){
    $con=mysqli_connect("localhost","uPower","","info"); 
    if (mysqli_connect_errno()) 
        echo "error DB";
    else{
        $query = "SELECT * FROM product"; 
        $result = mysqli_query ($con, $query);
        while($row = mysqli_fetch_assoc($result)){ 
            $nome = $row["name"];
            if(isset($_REQUEST["$name"])){  
                $qty = trim($_REQUEST['$row["name"]']);
                if($qty>0 && $qty<=$row["qty"]){
                    $new_qty = $row["qty"]-$qty;
                    $query2 = "UPDATE product SET qty = '$new_qty' WHERE qty = '".$row["qty"]."' ";
                    $result2 = mysqli_query ($con, $query2);
                    if($result){
                        echo "<table>";
                        echo "<tr><th>Name</th><th></th><th>Price</th></tr>";
                        do_content($row["name"],$qty,$row["price"]/100);
                        echo "</table>";
                    }   
                    else
                        echo "Error!";
                }

            }e

        }
        mysqli_free_result($result);
    }
mysqli_close($con); 
}

&GT;

<?php
 function do_content($name,$to_buy,$price){
    echo "<tr><th>$name</th><th>$to_buy</th><th>$price</th></tr>";
 }
?>

0 个答案:

没有答案