我的查询未将所选状态发送到数据库,
<?php
if( !isset( $_SESSION ) ){
session_start();
}
$con=mysqli_connect("localhost", "root", "", "test");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$number = mysqli_real_escape_string($con, $_POST['number']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$addressone = mysqli_real_escape_string($con, $_POST['addressone']);
$addresstwo = mysqli_real_escape_string($con, $_POST['addresstwo']);
$city = mysqli_real_escape_string($con, $_POST['city']);
$state = mysqli_real_escape_string($con, $_POST['state']);
$zip = mysqli_real_escape_string($con, $_POST['zip']);
$sql="UPDATE users SET `firstname`='$firstname', `lastname` = '$lastname',`number`='$number', `email` = '$email',`addressone`='$addressone', `addresstwo` = '$addresstwo',`city`='$city', `state` = '$state', `zip` = '$zip' WHERE `id`='" .$_SESSION['id']."'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
header("Location:dashboard.php");
mysqli_close($con);
?>
此表单的部分是
<div class="form-group">
<label class="col-md-5 control-label" for="state">State</label>
<div class="col-md-1">
<select id="state" name="state" class="form-control" value="<?php echo $state; ?>">
<option value="1">Select</option>
<option value="2">Alabama</option>
<option value="3">Alaska</option>
<option value="4">Arizona</option>
<option value="5">Arkansas</option>
<option value="6">California</option>
<option value="7">Colorado</option>
<option value="8">Connecticut</option>
<option value="9">Delaware</option>
<option value="10">District of Colombia</option>
<option value="11">Florida</option>
<option value="12">Georgia</option>
<option value="13">Hawaii</option>
<option value="14">Idaho</option>
<option value="15">Illinois</option>
<option value="16">Indiana</option>
<option value="17">Iowa</option>
<option value="18">Kansas</option>
<option value="19">Kentucky</option>
<option value="20">Louisiana</option>
<option value="21">Maine</option>
<option value="22">Maryland</option>
<option value="23">Massachusetts</option>
<option value="24">Michigan</option>
<option value="25">Minnesota</option>
<option value="26">Mississippi</option>
<option value="27">Missouri</option>
<option value="28">Montana</option>
<option value="29">Nebraska</option>
<option value="30">Nevada</option>
<option value="31">New Hampshire</option>
<option value="32">New Jersey</option>
<option value="33">New Mexico</option>
<option value="34">New York</option>
<option value="35">North Carolina</option>
<option value="36">North Dakota</option>
<option value="37">Ohio</option>
<option value="38">Oklahoma</option>
<option value="39">Oregon</option>
<option value="40">Pennsylvania</option>
<option value="41">Rhode Island</option>
<option value="42">South Carolina</option>
<option value="43">South Dakota</option>
<option value="44">Tennessee</option>
<option value="45">Texas</option>
<option value="46">Utah</option>
<option value="47">Vermont</option>
<option value="48">Washington</option>
<option value="49">West Virginia</option>
<option value="50">Wisconsin</option>
<option value="51">Wyoming</option>
<option value="52">American Samoa</option>
<option value="57">Federated States of Micronesia</option>
<option value="53">Guam</option>
<option value="58">Marshall Islands</option>
<option value="54">Northern Mariana Islands</option>
<option value="55">Puerto Rico</option>
<option value="56">Virgin Islands</option>
<option value="59">Palau</option>
<option value="60">AA</option>
<option value="61">AE</option>
<option value="62">AP</option>
</select>
</div>
</div>
答案 0 :(得分:-2)
您的查询错误
这一个
$sql="UPDATE users SET `firstname`='$firstname', `lastname` = '$lastname',`number`='$number', `email` = '$email',`addressone`='$addressone', `addresstwo` = '$addresstwo',`city`='$city', `state` = '$state', `zip` = '$zip' WHERE `id`='" .$_SESSION['id']."'";
删除``
它应该是这样的
$sql="UPDATE users SET firstname='$firstname', lastname = '$lastname',number='$number', email = '$email',addressone='$addressone', addresstwo= '$addresstwo',`city`='$city', state = '$state', zip = '$zip' WHERE id='" .$_SESSION['id']."'";