Hi
I am new in PHP. I have used dropdown to bind with my sql data. It is ok
But I could not insert data into table only from dropdown. Other controls like text can be inserted.
I have given code below.
Pls advise me.
Maideen

<?php require_once '../inc/header.php'; ?>
      <div class="portlet light bordered">
          <div class="portlet-title">
              <div class="caption">
                  <i class="icon-social-dribbble font-green"></i>
                  <span class="caption-subject font-green bold uppercase">Parameter</span>
              </div>
          </div>
         <form class="forget-form" action="../classes/cls.parameter.php" method="POST">
             <div class="portlet-body">
                 <div class="form-group">
                     <label for="default" class="control-label">Parameter Details</label>
                     <input id="default" type="text" class="form-control" placeholder="Parameter Details" name="paramdetails"> 
                 </div>
                 <div class="form-group">
                     <label for="single" class="control-label">Parameter head</label>
                     <select id="paramhead" class="form-control select2" name="paramhead">
                         <option>-- Select --</option>
                         <?php
                               $sql  = "select * from tbl_paramhead order by paramhead";
                               $stmt   = $pdo->prepare($sql);
                               $stmt->execute();
                                   while ($row = $stmt->fetch())
                                   {
                                     echo '<option value>' .$row['paramhead']. '</option>'; 
                                   } 
                         ?>
                     </select>
                 </div>
             </div>
         <div class="form-actions">
             <button type="submit" class="btn green uppercase btn btn-danger mt-ladda-btn ladda-button" data-style="zoom-out" name="paramhead">Submit</button>
         </div> 
     </form>    
     </div>
 <?php require_once '../inc/footer.php'; ?>

<?php
  require_once '../inc/config.php';
  if(isset($_POST['paramhead']))
  {
      if($_SERVER["REQUEST_METHOD"] == "POST")
      {
        $paramhead =$_POST['paramhead'];
        $paramdetails =$_POST['paramdetails'];
       $bool = true;
       $sql="insert into tbl_parameter(paramhead,paramdetails) values ('$paramhead','$paramdetails')";
       $stmt=$pdo->prepare($sql);
       $stmt->execute();
       $pdo = null;
       print '<script>alert("Saved");</script>';
       print '<script>window.location.assign("../admin/parameter.php");</script>';      
     }
 }  
 ?>

You're not giving the option a value so no data is getting passed back in the POST for that variable.

You need to chnage this:
echo '<option value>' .$row['paramhead']. '</option>';

to:
echo '<option value="' . $row['paramhead'] . '">' .$row['paramhead']. '</option>';

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.