PHP表单POST变量为空
我试图使用HTTPPOST将变量从PHP表单POST变量为空,php,html,mysql,Php,Html,Mysql,我试图使用HTTPPOST将变量从delivery.php传递到delivery insert.php。提交后,不会传入任何变量 下面是delivery.php <form action="delivery-insert.php" method="post"> <div class="form-group"> <label>Delivery No.</label>
delivery.php
传递到delivery insert.php
。提交后,不会传入任何变量
下面是delivery.php
<form action="delivery-insert.php" method="post">
<div class="form-group">
<label>Delivery No.</label>
<input type="text" class="form-control" id="deliverynoinput" placeholder="D0" required> <br>
<label>Price</label>
<input type="number" class="form-control" id="deliverypriceinput" placeholder="0" required> <br>
<label>Quantity</label>
<input type="number" class="form-control" id="deliveryquantityinput" placeholder="0" required>
</div>
<div class="form-group">
<label for="selectTruckInput">Select Delivery Truck</label>
<select class="form-control" id="selectTruckInput">
<?php
foreach ($trucks as $i => $value) {
print "<option>" . $value . "</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="selectCustomerInput">Select Delivery Customer</label>
<select class="form-control" id="selectCustomerInput">
<?php
foreach ($customers as $i => $value) {
print "<option>" . $value . "</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="selectDriverInput">Select Delivery Driver</label>
<select class="form-control" id="selectDriverInput">
<?php
foreach ($drivers as $i => $value) {
print "<option>" . $value . "</option>";
}
?>
</select>
</div>
<input type="submit"/>
</form>
有人知道为什么我所有的变量都是空的吗?您需要在输入中使用该属性。这样,浏览器将发送相应的名称作为
$\u POST
的键。这甚至适用于阵列
e。g
表单使用
name
属性,而您没有属性。
<html>
<body>
<?php
$host = "localhost";
$user = "root";
$pw = "root";
$db = "project";
$con = new mysqli($host, $user, $pw, $db);
if (! $con) {
die("Connection failed: " . mysqli_connect_error());
}
$dno = $_POST['deliverynoinput'];
$dprice = intval($_POST['deliverypriceinput']);
$dquant = intval($_POST['deliveryquantityinput']);
$dtruck = $_POST['selectTruckInput'];
$dcust = $_POST['selectCustomerInput'];
$ddriver = $_POST['selectDriverInput'];
print '<h1>Here</h1>';
print '<h1>'.$dno.'</h1>';
print $_POST['selectTruckInput'];
$sql = "INSERT INTO delivery (deliveryno, price, truckid, custphoneno, driverid) VALUES ('$dno','$dprice','$dtruck','$dcust','$ddriver')";
if (mysqli_query($con, $sql)) {
print "added to delivery successfully";
} else {
print "Error: " . mysqli_error($con);
}
$sql = "INSERT INTO deliveryquantity (deliveryno, quantity) VALUES ('$dno', '$dquant')";
if (mysqli_query($con, $sql)) {
print "added to deliveryquantity successfully";
} else {
print "Error: " . mysqli_error($con);
}
$con->close();
?>
</body>
</html>
<!-- Single Value -->
<input name="someValue" />
<!-- Array -->
<input name="someArray[]" />
<input name="someArray[]" />
// Single value
$_POST['someValue']
// Array
$_POST['someArray'][$numericIndex]