我在表格中有一个选择框,该框应将['地址']发布到操作页面。在操作页面上,我回显了包含$ _POST ['address']的变量,而我仅得到该地址的一部分。 例如,地址为“ 123 Accent Ln”。我只得到“ 123”。如果我也在数据库中选择其他地址,则会发生这种情况。 预先感谢您的评论和支持,如果您需要我显示更多代码,请告诉我。
我的代码: (address.php)
<form id='form'action="cart/3dbinpack/3DBP.php" method="post">
<?php
error_reporting(E_ALL);
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "secure_login";
$username=$_SESSION['login_user'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT first_name, last_name, address, city, state, zip FROM address
WHERE username = '$username'";
$result = $conn->query($sql);
if (!$result) {
trigger_error('Invalid query: ' . $conn->error);
}
if ($result->num_rows > 0) {
// output data of each row
echo "<select required name='address'>";
while($row = $result->fetch_assoc()) {
echo "<option value=" . $row['address'] .">".$row['first_name'].'-'.
$row['last_name'] .'-'. $row['address'].'-'.$row['city'].'-'.$row['state'].'-
'.$row['zip']."</option>";
}
} else {
echo "<option value=''> No address on file </option>";
}
echo "</select>";
?>
<input type="checkbox" name="active" value="1"> Make default shipping
location<br>
<input type="submit" value="Quote Shipping">
</form>
3DBP.php
$address= $_POST['address'];
echo $address;
$query = "select zip from address WHERE username= '$username' AND
address='$address'";
$result = mysqli_query($conn,$query);
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));}
while($row = $result->fetch_assoc()) {
$zip = $row['zip'];
}
exit();