【问题标题】:PHP Form Submision with jQuery Mobile使用 jQuery Mobile 提交 PHP 表单
【发布时间】:2013-10-15 09:28:42
【问题描述】:

这是我的 jquery 移动应用程序代码。但是我使用php 结果创建的表单不起作用。表单未在提交时发布数据。我什至试过data-ajax="flase"

<table id="stock">
<? $sql = mysqli_query($con, "SELECT * FROM products WHERE `product_id` = '1'");
    while($row=mysqli_fetch_array($sql)){
        $name = $row['name'];
        $chamecal = $row['chamecal'];
        $price = $row['selling_price'];
        $bprice = $row['buying_price'];
        $quantity = $row['quantity'];
        $manufacturer = $row['manufacturer'];
        $date = $row['date'];
        $edate = $row['expire'];
        $pid = $row['product_id'];
?>
   <form id="stockupdate" method="post" action="medupdate.php">
    <tr>
        <td><?=$name;?></td>
        <td><?=$chamecal;?></td>
        <td><?=$manufacturer;?></td>
        <td><input type="text" name="medbprice" value="<?=$bprice;?>" /></td>
        <td><input type="text" name="medprice" value="<?=$price;?>" /></td>
        <td><?=$date;?></td>
        <td><?=$edate;?></td>
        <td><input type="text" name="medstock" value="<?=$quantity;?>" /></td>
        <td class="ui-screen-hidden"><input type="text" name="pid" value="<?=$pid;?>" /></td>
        <td>
            <input type="submit" title="Update" data-icon="gear" data-theme="f" data-inline="true" data-iconpos="notext" />
        </td>
    </tr>
<?    
    } 
?>
</form>
</table>

值处理程序文件medupdate.php

<?php session_start();?>
<?php include_once('include/config.php');?>
<?
$pid        = $_POST['pid'];
$medbprice  = $_POST['medbprice'];
$medprice   = $_POST['medprice'];
$medstock   = $_POST['medstock'];

$sql = mysqli_query($con, "UPDATE `products` SET `quantity` = '$medstock', `buying_price` = '$medbprice' , `selling_price` = '$medprice' WHERE `product_id` = '$pid'");

if($sql){
echo 1;
}
?>

【问题讨论】:

  • 我们需要查看处理发布值的代码。我在您发布的代码中看不到单个 $_POST 全局变量。如果上面的代码是完整的,它不会处理你的任何表单数据......在谷歌搜索“PHP 处理发布的值”等。
  • @R.大卫这是一个移动应用程序还是常规网站,支持响应式的 jquery mobile ...?
  • @SathyaRaj 常规网站,支持 jquery mobile 以实现响应。
  • 你是想写data-ajax="false"还是你真的有="flase"
  • 我试过data-ajax="false"。不管有人回答我的问题。问题出在&lt;form&gt;&lt;table&gt;

标签: php jquery ajax forms jquery-mobile


【解决方案1】:

如果我冒险猜测,那是因为你在放置

<form id="stockupdate" method="post" action="medupdate.php">

直接在表格元素内(这是无效标记)。把它移到你的桌子外面(在你的&lt;table&gt; 之前)。当您创建无效标记时,浏览器引擎会尝试更正它,这可能会导致此类问题。

这就是 chrome 对您的标记所做的:

【讨论】:

  • 这是一个有效的观点,但他实际上并没有在他的代码中的任何地方处理 POSTED 值。
【解决方案2】:

你不能按照html结构,form里面table之类的,

<table>
   <form>
     <tr>
        <td>
        </td>
     </tr>
   </form>
</table>

这是工作代码,

表单 php

<!DOCTYPE html>


<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    </head>



    <body>
        <form id="stockupdate" method="post" action="medupdate.php" data-ajax="false">
            <table>
                <tr>
                    <td><input type="text" name="medbprice" value="xxxx" /></td>
                    <td><input type="text" name="medprice" value="yyyyy" /></td>
                    <td><input type="text" name="medstock" value="zzzzzz" /></td>
                    <td class="ui-screen-hidden"><input type="text" name="pid" value="111111" /></td>
                    <td>
                        <input type="submit" title="Update" data-icon="gear" data-theme="f" data-inline="true" data-iconpos="notext" />
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

medupdate.php

<?php 
session_start();
$pid        = $_POST['pid'];
$medbprice  = $_POST['medbprice'];
$medprice   = $_POST['medprice'];
$medstock   = $_POST['medstock'];
echo $pid;
// your database operations
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    相关资源
    最近更新 更多