某些表单输入未通过 GET / POST 发送 [重复]

Posted

技术标签:

【中文标题】某些表单输入未通过 GET / POST 发送 [重复]【英文标题】:Some Form Inputs didn't sent via GET / POST [duplicate] 【发布时间】:2015-08-30 06:58:55 【问题描述】:

这是我的更新项目.php

<!DOCTYPE html>
<html lang="en">

<head>
<style type="text/css">
input[type='text'],input[type='number'],input[type='date']
color:#0000FF;
background-color:#FFFFCC;


</style>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Update-ITEM| PDS</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>
<?php
$servername = "127.0.0.1";
$username = "root";
// Create connection
$conn = mysql_connect($servername, $username,"");
$id=$_GET["id"];

// Check connection
if (!$conn) 

exit();

else

$id=$_GET["id"];

$sql="select Item_code,Item_name,Department,Make,vat,cost,packing,unit,Exp_Date,Stock,Description from item_master where Item_code=$id";

mysql_select_db('pds', $conn);

$result = mysql_query($sql);

if (!$result) 

 echo "<script type='text/javascript'>alert('error');</script>";  

else

$row = mysql_fetch_array( $result );
$name=$row['Item_name'];
$vat=$row['vat'];
$cost=$row['cost'];
$packing=$row['packing'];
$unit=$row['unit'];
$ex=$row['Exp_Date'];
$stock=$row['Stock'];
$desc=$row['Description'];
$dept=$row['Department'];
$make=$row['Make'];

?>
    <div id="wrapper">

        <!-- Navigation -->

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">PDS</a>
            </div>
            <!-- Top Menu Items -->
            <ul class="nav navbar-right top-nav">

                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i>  <?php
 session_start();
 if(isset($_SESSION['User']))

$s1=$_SESSION['User'];
echo $s1;

else

header('Location:login.html');

session_destroy();
 
?> <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="/logout.php"><i class="fa fa-fw fa-power-off"></i> Log Out</a>
                        </li>

<li>
          <a href="Change Password2.php">Change Password</a>
                            </li>
                    </ul>
                </li>
            </ul>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav side-nav">
                    <li>
                        <a href="./home.php"><i class="fa fa-fw fa-home"></i>HOME</a>                       </li>
                        <li class="active">
                        <a href="javascript:;" data-toggle="collapse" data-target="#demo11"><i class="fa fa-fw fa-tasks"></i>Item-Master<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo11" class="collapse">
                            <li>
                                <a href="./view item">View Item</a>                            </li>
                            <li>
                                <a href="./Add item.php" accesskey="i">Add Item</a>                            </li>
                        </ul>
                    </li>
                        <li>
                        <a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-bus"></i>Make-Master<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo" class="collapse">
                            <li>
                                <a href="./view make">View Make</a>                            </li>
                            <li>
                                <a href="./Add make.php">Add Make</a>                            </li>
                        </ul>
                    </li>

                        <li>
                        <a href="javascript:;" data-toggle="collapse" data-target="#demo2"><i class="fa fa-fw fa-plus-square"></i>Department Mater<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo2" class="collapse">
                            <li>
                                <a href="./view dept">View Department</a>                            </li>
                            <li>
                                <a href="./Add department.php">Add Department</a>                            </li>
                        </ul>
                    </li>

                        <li>
                        <a href="javascript:;" data-toggle="collapse" data-target="#demo3"><i class="fa fa-fw fa-shopping-cart"></i>Sales<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo3" class="collapse">
                            <li>
                                <a href="./view sales">View Sales</a>                            </li>
                            <li>
                                <a href="./Add sales.php">Add Sales</a>                            </li>
                          </ul>
                    </li>
                    <li>
                    <a href="javascript:;" data-toggle="collapse" data-target="#demo4"><i class="fa fa-fw fa-plus"></i>Purchase<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo4" class="collapse">
                            <li>
                                <a href="./view purchase">View Purchase</a>                            </li>
                            <li>
                                <a href="./Add purchase.php">Add Purchase</a>                            </li>
                      </ul>
                    </li>

                        <li>
                        <a href="javascript:;" data-toggle="collapse" data-target="#demo5"><i class="fa fa-fw fa-users"></i>Accounts<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo5" class="collapse">
                            <li>
                                <a href="./view account">View Account</a>                            </li>
                            <li>
                                <a href="./Add account.php">Add Account</a>                            </li>
                          </ul>
                    </li>

                        <li>
                        <a href="javascript:;" data-toggle="collapse" data-target="#demo6"><i class="fa fa-fw fa-users"></i>Users<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo6" class="collapse">
                            <li>
                                <a href="./view user">View Users</a>                            </li>
                            <li>
                                <a href="./Add user.php">Add Users</a>                            </li>
                          </ul>
                    </li>       </nav>


        <div id="page-wrapper">

            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                          Update Item
                        </h1>
                        <ol class="breadcrumb">
                            <li>
                                <i class="fa fa-dashboard"></i>  <a href="index.html">PDS</a>
                            </li>
                            <li class="active">
                                <i class="fa fa-edit"></i>  Update Item
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->

                <div class="row">
                    <div class="col-lg-6">

                     <form role="form" method="get" action="update-item.php">

                            <div class="form-group">
                                <label>Item Code</label>
                                <input type="text" class="form-control" name="id" placeholder="Enter Itemcode" required value="<?php echo htmlentities($id);?>" disabled="disabled">
                            </div>

                                <div class="form-group">
                                <label>Item Name</label>
                                <input type="text" class="form-control" name="name" placeholder="Enter Itemname" required value="<?php echo htmlentities($name);?>" disabled="disabled">
                            </div>


                <div class="form-group">
         <label>Department</label>
         <select class="form-control" style="background-color:#FFFFCC; color:#0000FF;" name="dept" required>
             <option disabled="disabled" selected="selected">Current :<?php echo $dept ?>
             </option>
             <?php
                $link = mysqli_connect("127.0.0.1", "root", "","pds");
                $SqlResult = mysqli_query($link, "SELECT department_name from department_master");

                while($Row = mysqli_fetch_array($SqlResult))
                
                  ?>
                 <option name="dept" value="<?php echo $Row['department_name']; ?>"><?php echo $Row['department_name']; ?></option>
                <?php 
                
                ?>
        </select>

</div>

                            <div class="form-group">
                                <label>Make:-</label>
                               <select style="background-color:#FFFFCC; color:#0000FF;" class="form-control" name="make" required>
             <option disabled="disabled" selected="selected">Curent :<?php echo $make ?>
                                                        <?php
                $link = mysqli_connect("127.0.0.1", "root", "","pds");
$SqlResult = mysqli_query($link, "SELECT make_name from make_master");

while($Row = mysqli_fetch_array($SqlResult))

  ?>
   <option value="<?php echo $Row['make_name']; ?>"><?php echo $Row['make_name']; ?>
<?php 

?>
                                </select>
                            </div>

                           <div class="form-group">
                                <label>Vat:-</label>
                               <input type="text" class="form-control" name="vat" placeholder="Enter vat Percentage (%)" required value="<?php echo htmlentities($vat);?>">
                            </select>
                            </div>

                            <div class="form-group ">
                                <label>Cost/Sell Rate:-</label>
                               <input type="text" class="form-control" name="mrp" placeholder="Enter Cost/Sell Rate $$$" required value="<?php echo htmlentities($cost);?>">
                              </select>
                                </div>
                                <p>.</p>

                            <div class="form-group col-md-6 col-sm-12 col-xs-12 col-lg-6">
                                <label>Packing:-</label>
                               <input type="text" class="form-control"  name="pack" placeholder="Enter Packing Like (1x100)" required value="<?php echo htmlentities($packing);?>">
                           </div>
                           <div class="form-group col-md-6 col-sm-12 col-xs-12 col-lg-6">
                                <label>Unit:-</label>
                               <input type="text" class="form-control" name="unit" placeholder="Enter Unit Like liter/gm/kg"  style="float:left;" required  value="<?php echo htmlentities($unit);?>">


                            </div>
                            <br /><br /><br /><br /><br />  <br />
                            <div class="form-group">
                                <label>Expiry Date:-</label>
                               <input type="date" class="form-control" name="ex" placeholder="Enter Expirydate" required value="<?php echo htmlentities($ex);?>">
                                </div>
                            <div class="form-group">
                                <label>Stock:-</label>
                               <input type="number" class="form-control" name="stock" placeholder="Enter Stock:-" required  value="<?php echo htmlentities($stock);?>">


                            </div>

                            <div class="form-group">
                                <label>Description:-</label>
                               <textarea style="color:#0000FF; background-color:#FFFFCC;" class="form-control" name="desc" placeholder="Enter Stock:-" required value="<?php echo htmlentities($desc);?>">
                                </textarea>

                            </div>


                            <br />



        <button type="submit" class="btn btn-default">Submit</button>
        <button type="reset" class="btn btn-default">Reset</button>

                        </ form>


                    </div>
                </div>
                <!-- /.row -->

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

</body>

</html>

这是更新数据的第二个文件:-Update-item.php

<?php
$servername = "127.0.0.1";
$username = "root";
// Create connection
$conn = mysql_connect($servername, $username,"");

// Check connection
if (!$conn) 

exit();

else

$id=$_GET['id'];
$name=$_GET['name'];
$dept=$_GET['dept'];
$make=$_GET['make'];


$vat=$_GET['vat'];
$mrp=$_GET['mrp'];
$pack=$_GET['pack'];
$unit=$_GET['unit'];


$ex=$_GET['ex'];

$stock=$_GET['stock'];

$desc=$_GET['desc'];
echo "id=",$id;
echo "dept=",$dept;
echo "make=",$make;
echo "name=",$name;

echo "vat=",$vat;

echo "mrp=",$mrp;

echo "pack=",$pack;


?>

输出是:-

id=dept=make=name=vat=4mrp=100pack=1*100

我无法获取变量 ID、名称、部门、品牌的值。

它是网址

http://127.0.0.1:8888/Pharmaceutical%20Distribution%20System/PDS/update-item.php?vat=4&mrp=100&pack=1*100&unit=ml&ex=2015-12-31&stock=0&desc=++++++++++++++++++++++++++++%09

【问题讨论】:

这是很多代码。 id 字段是否会因禁用而改变? ***.com/questions/8925716/… 我在您的脚本中观察到的其他问题,您正在混合使用 mysql 和 mysqli 驱动程序。您的代码对 SQL 注入开放。 【参考方案1】:

编辑 2: 删除了不相关的信息。

编辑: disabled inputs are not posted

【讨论】:

我知道,但问题是为什么数据不在 URL 中! 这是评论,不是答案。 @chris85,我的声望等级不允许添加 cmets。感谢您的反对。 你为什么不写一个与问题相关的答案,我会取消反对票。删除错误的You are trying to $_GET['id'] in Update-item.php, but your pasted URL doesn't contain such query parameter.,因为这与问题无关。

以上是关于某些表单输入未通过 GET / POST 发送 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

未收到 WinHttp POST 正文

Django 表单未接收输入

_POST,_GET,_REQUEST区分

_POST,_GET,_REQUEST区分

10_常见的get和post请求_路由器_ejs服务器渲染模板引擎

PHP $_GET与$_POST 变量