在PHP,MySql?</p>中的<p>标签中获取数据库值

时间:2014-10-27 06:22:46

标签: php mysql

我想在html

标签中获取数据库值,是否可能?我可以使用此代码

在文本框中获取数据库值
$con = mysqli_connect("localhost", "root", "", "hct_db"); // Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security 
$client_id = mysqli_real_escape_string($con, $_POST['client_id']);
$result = mysqli_query($con, "SELECT * FROM client where client_id = '" . $client_id . "'");
while ($row = mysqli_fetch_array($result)) {

   <input class="form-control" name="client_id1" value="<?php echo( htmlspecialchars( $row['address'] ) ); ?>" />

3 个答案:

答案 0 :(得分:0)

是的,你可以做到。首先,使用查询检索数据并将其保留为数组,然后回显它。

答案 1 :(得分:0)

是的,你可以尝试这个,请在​​发布问题之前尝试一下......

<?php 
$con=mysqli_connect("localhost","root","","hct_db"); // Check connection 
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} // escape variables for security 

$client_id  = mysqli_real_escape_string($con, $_POST['client_id']); 
$result     = mysqli_query($con,"SELECT * FROM client where client_id = '".$client_id."'"); 

while($row = mysqli_fetch_array($result)) {  //this is my retrieve code, what to do next ? ?>
    <a href="#"><? echo $row[0]; ?></a> // href tag
    <h2><? echo $row[0]; ?></h2>    //h tag
    <p><? echo $row[0]; ?></p>  //p tag 
    //and so on
<?}?>

评论进一步查询...

答案 2 :(得分:0)

试试这个(它会用值填充你的输入框)

 <?php

$con = mysqli_connect("localhost", "root", "", "hct_db"); // Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security 
$client_id = mysqli_real_escape_string($con, $_POST['client_id']);
$result = mysqli_query($con, "SELECT * FROM client where client_id = '" . $client_id . "'");

echo '<form action="" method="post">';//openning upthe 
while ($row = mysqli_fetch_array($result)) {

    echo '<p>'.( htmlspecialchars( $row['address'] ) ).'</p>';
 }