Jump to content

display data in input text and Option from my sql using php


Recommended Posts

Hi

 

I could not load data into input text and select option control.

I don't know where i did wrong.

Pls advice  me

Thank you in advence

 

maideen

<?php require_once '../inc/header.php'; ?>

<?php

if($_SERVER["REQUEST_METHOD"] == "GET")
    {
        $id=$_GET['id'];
        $sql ="Select * from tbl_parameter where id ='$id'";
        $stmt = $pdo->prepare($sql);
        $stmt->execute();
            while ($row = $stmt->fetch())
            {
                $paramhead =$row['paramhead'];
                $paramdetails =$row['paramdetails'];
                $id =$row['id'];

            // below is display information in page. It is OK
                
              echo "id entered is :",$id,"<br>";
              echo "paramHead entered is :",$paramhead,"<br>";
              echo "Param details entered is :",$paramdetails,"<br>";                            
            }
    }
  
?>
    <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">Update Parameter</span>
            </div>
        </div>
        
        <div class="portlet-body">
            
                <form  action="../classes/cls.parameter.php" method="POST">
                    <div class="form-group">
                        <label for="default" class="control-label">Parameter Details</label>
                        <input id="paramdetails" type="text" class="form-control" placeholder="Parameter Details" name="paramdetails" values ="<?php echo $paramdetails; ?>" >
                    </div>
                    <div class="form-group">
                        <label for="single" class="control-label">Parameter head</label>
                        <select id="paramhead" name="paramhead" class="form-control select2" >
                            <option>-- Select --</option>
                            <?php
                                  $sql  = "select * from tbl_paramhead order by paramhead";
                                  $stmt = $pdo->prepare($sql);
                                  $stmt->execute();
                                      while ($row = $stmt->fetch())
                                      {
                                        $optvalue = $row['paramhead'];
                                        print '<option value ='.$optvalue.'>' .$row['paramhead']. '</option>'; 
                                        //echo '<option value ='.$row['paramhead'].'>' .$row['paramhead']. '</option>';
                                      } 
                            ?>
                        </select>                    

                    </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="add">Submit</button>
                    </div> 
                </form>    
        </div>
    </div>


<?php require_once '../inc/footer.php'; ?>



Link to post
Share on other sites

The point of using PDO is so you do not put $id directly into your query. Do some more reading on how to use that correctly.

 

Also add some error checking. Assuming no errors, your code should work. If it's not, then you're getting errors you're not seeing and accounting for.

Link to post
Share on other sites

the value attribute in your text form field is misspelled. it's not values

 

as to how to select the correct option choice, you would output the selected attribute in the correct <option ,,,> tag, by comparing the current value being output inside the while loop with the value in $paramhead.

Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.