如何在php中的文本框中显示数据库中的数据

时间:2016-12-16 15:52:14

标签: javascript php mysql

我是php编程的新手我在这段代码中有问题,我想在文本框中显示数据当我按下网格中的选择按钮,但我卡在上面因为数据没有显示在文本框和我的选择按钮也不起作用,我为此做的朋友, 这是我的代码enter image description here

第一个名字                          中间名字                          姓                           

**--//php code--//**

$qrydatabind='SELECT ecode, first_name, middle_name, last_name, father_name, mother_name,
          number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
          email_id, adhar_id, pan_number, passport_number, tin_number, dl_number FROM USER_MASTER ORDER BY user_id DESC 
          LIMIT 1';
                  $results=  mysql_query($qrydatabind) or die(mysql_error());

                      while( $row =  mysql_fetch_array( $results ) ) {
                        echo
            "
                <div class='table-responsive'>
<table  border='1' style= 'background-color: #84ed86; color: #761a9b;  ' >
      <thead>
                <tr>
            <th></th>
              <th>Entity Code</th>
              <th>User Id</th> <th>User Name</th> <th>Father Name</th>  <th>Mother Name</th>  <th>No.Of Dependents</th>
              <th>D.O.B</th> <th>GENDER</th> <th>Id Mark</th> <th>MARITAL STATUS</th>  <th>SPOUSE NAME</th>
              <th>Mob. Number</th> <th>E-Id</th> <th>ADHAR-ID</th> <th>PAN-No.</th> <th>PASSPORT-No.</th>
               <th>TIN-NO.</th> <th>DL-No.</th>
            </tr>
                </thead>

                      <tr >        

                        <td><button type='submit' class='btn btn-primary' name='select_button'>Select</button> </td> 
                        <td>{$row['ecode']}</td> <td> echo $row[0];</td>
                        <td>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</td>             
                        <td>{$row['father_name']}</td> <td>{$row['mother_name']}</td>
                        <td>{$row['number_of_dependents']}</td> <td>{$row['dob']}</td>
                        <td>{$row['gender']}</td> <td>{$row['identification_mark']}</td>
                        <td>{$row['marital_status']}</td> <td>{$row['spouse_name']}</td>
                        <td>{$row['mobile_number']}</td> <td>{$row['email_id']}</td>
                        <td>{$row['adhar_id']}</td>  <td>{$row['pan_number']}</td>
                        <td>{$row['passport_number']}</td> <td>{$row['tin_number']}</td>
                        <td>{$row['dl_number']}</td>

            </tr> </table>  
              </div>";
        }}

        if(isset($_POST['select_button']))
            {
             $qrydatabind1='SELECT ecode, first_name, middle_name, last_name, father_name, mother_name,
          number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
          email_id, adhar_id, pan_number, passport_number, tin_number, dl_number FROM USER_MASTER';
                  $results1=  mysql_query($qrydatabind1) or die(mysql_error());

                      while( $row =  mysql_fetch_array( $results1 ) ) {
                          echo'
                        <tr >                   
                        <td> </td> 

                         <td><input  type="text" value="{$row["first_name"]}" ></td>

            </tr>';

            }
            }

3 个答案:

答案 0 :(得分:1)

很简单。当你把数据放进去时。

您的代码

<td> echo $row[0];</td>

文本框代码:

<input type="text" value="<?php echo $row[0];?>">

答案 1 :(得分:1)

PHP变量只会在以双引号引用的字符串中进行评估"

你应该结合一个字符串:

echo '<td><input type="text" value="' . $row["first_name"] . '" ></td>';

或者,使用<?php?>在脚本和标记之间切换

while( $row =  mysql_fetch_array( $results1 ) ) {

    ?><td><input type="text" value="<?php echo $row["first_name"]; ?>" ></td><?php

}

答案 2 :(得分:0)

You can also use this as 
echo'<tr><td><input  type="text" value="'.$row["first_name"].'" ></td></tr>';