-6ren">
gpt4 book ai didi

php - 数据库的下拉选项

转载 作者:行者123 更新时间:2023-11-30 23:53:19 25 4
gpt4 key购买 nike

我的查询没有将选择的状态发送到数据库,

<?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>

最佳答案

你的查询是错误的

这个

$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']."'";

关于php - 数据库的下拉选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26014170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com