如何在php中将php变量设置为html输入标签

时间:2018-03-27 07:05:48

标签: php html mysql

我需要如何设置变量值为html输入标签,我有一个变量值我需要传递html标签请帮助。

我的mysql代码:

<?php
//error_reporting(0);
include('db_connection.php');
 if (isset($_POST['submit1'])) {
        $skills = $_POST["skills"];
        //print_r($skills);die;
    }
$sql ="SELECT * FROM `tbl_master_property` WHERE `name` ='$skills'";
  $result=$conn->query($sql);
   while( $row = $result->fetch_assoc() ) { 
    $project[] = $row;
}
foreach ($project as $value) {
  $pg_address = $value['pg_address'];
  $pg_owner = $value['pg_incharge_name'];
} 
?>

Html代码:

<div class="col-lg-12 form-group">
            <label>Address</label>
            <input class="border col-lg-12" type="text" name= "address" value ="<?php echo $value['pg_address']; ?>" required/>
          </div>
          <div class="col-lg-12 form-group">
            <label>PG Owner Name</label>
            <input class="border" type="text" name= "pg_owner_name" value ="<?php echo $value['pg_owner']; ?>"  required />
          </div>

2 个答案:

答案 0 :(得分:0)

试试这个, 对于表中的每一行,它将在输入框中回显地址和项目所有者名称,

 <?php
//error_reporting(0);
include('db_connection.php');
 if (isset($_POST['submit1'])) {
        $skills = $_POST["skills"];
        //print_r($skills);die;
    }
$sql ="SELECT * FROM `tbl_master_property` WHERE `name` ='$skills'";
  $result=$conn->query($sql);
   while( $row = $result->fetch_assoc() ) { 
    $project[] = $row;
}
foreach ($project as $value) {
  $pg_address = $value['pg_address'];
  $pg_owner = $value['pg_incharge_name'];
  echo '<div class="col-lg-12 form-group">
            <label>Address</label>
            <input class="border col-lg-12" type="text" name= "address" value ="'.$pg_address.'" required/>
        </div>
        <div class="col-lg-12 form-group">
            <label>PG Owner Name</label>
            <input class="border" type="text" name= "pg_owner_name" value ="'.$pg_owner.'"  required />
        </div>';
} 
?>

答案 1 :(得分:-1)

<?php
if (isset($_POST['submit1'])) {
    $skills = $_POST["skills"];
    $sql ="SELECT * FROM `tbl_master_property` WHERE `name` ='$skills'";
    $result=$conn->query($sql);
    $row = $result->fetch_assoc();
    $value= $row[0];
}
?>


<input type="text" name="address" value="<?php echo $value['pg_address'];?>">
<input type="text" name="pg_owner_name" value="<?php echo $value['pg_owner'];?>">