php - Drodown option to database -
my query not sending chosen state database,
<?php if( !isset( $_session ) ){ session_start(); } $con=mysqli_connect("localhost", "root", "", "test"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } // escape variables 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' `id`='" .$_session['id']."'"; if (!mysqli_query($con,$sql)) { die('error: ' . mysqli_error($con)); } header("location:dashboard.php"); mysqli_close($con); ?>
the part of form is
<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>
your query wrong
this 1
$sql="update users set `firstname`='$firstname', `lastname` = '$lastname',`number`='$number', `email` = '$email',`addressone`='$addressone', `addresstwo` = '$addresstwo',`city`='$city', `state` = '$state', `zip` = '$zip' `id`='" .$_session['id']."'";
remove ``
its should
$sql="update users set firstname='$firstname', lastname = '$lastname',number='$number', email = '$email',addressone='$addressone', addresstwo= '$addresstwo',`city`='$city', state = '$state', zip = '$zip' id='" .$_session['id']."'";
Comments
Post a Comment