php - Database driven select box being empty on submit -


i trying submit form value in database php. in form select box value comes database.

<?php include_once 'header.php'; $sql="select uid,name emitra_basic block='$user'"; $result = $conn->query($sql); //form validion  if(isset($_post['submit']))    {   $eid =$_post["eid"];   if($eid=="blank")  {      $flag=1;   $iderr="please select e-mitra";  } $miatm =trim($_post["miatm"]);  if(empty($miatm) || !preg_match("/^[a-za-z0-9 ]*$/",$miatm)) { $flag=1;  $mierr="please enter valid id";  }  .............like if($flag==0) { $sqll="insert **********";   } 

//my form is

<form id="basic" method="post" name="basic">  <select class="select-style gender" name="eid">         <option value="blank">please select e-mitra id</option>         <?php  while($row=mysqli_fetch_array($result))  { ?>   <option value="<?php echo $row['uid']; ?>"><?php echo $row['uid']." (" . $row['name'] .")"; ?></option> <?php  } ?> </select>      <p class="contact"><label for="bid">micro-atm serial no</label></p>  <input type="text" name="miatm" value ="<?php if (isset($miatm)) echo $miatm; ?>"    /> <?php echo $mierr; ?>   <p class="contact"><label for="bid">micro-atm tid no</label></p>  <input type="text" name="tid" value ="<?php if (isset($tid)) echo $tid; ?>" /> <?php echo $tierr; ?>     <input class="buttom" name="submit" id="submit"  value="add me" type="submit">     

its seems ok.but when tried submit form if of 1 field remain empty show blank value in select box. how can remain same selected value in select box if textbox remain empty.

you need retain value of drop down after form submit.

user selected attribute of select option.

<?php if (isset($_post['submit'])) {   $eid =$_post["eid"];   if ($eid=="blank") {     $flag=1;     $iderr="please select e-mitra";   } } $sql="select uid,name emitra_basic block='$user'"; $result = $conn->query($sql); ?> <select class="select-style gender" name="eid"> <option value="blank">please select e-mitra id</option> <?php while($row=mysqli_fetch_array($result)) {   $selected = (isset($_post["eid"]) && $_post["eid"] == $row['uid']) ? 'selected="selected"' : ''; ?>   <option value="<?php echo $row['uid']; ?>" <?php echo $selected;?>><?php echo $row['uid']." (" . $row['name'] .")"; ?></option> <?php  } ?> </select> 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -