我试图从我的数据库中提取数据并将其放入文本框中,以便更新。

时间:2017-04-24 21:32:40

标签: php html

这是我的代码 我的目标是能够从数据库中获取数据并将其放在文本框中,以便用户可以更新其配置文件。我还没有得到更新功能。现在我想弄清楚如何在文本框中显示数据

<?php

 $userID = htmlspecialchars($_GET["userID"]);
 $lastName = htmlspecialchars($_GET["lastName"]);
 $_SESSION["userID"] = $userID;

include 'inc/connect.php';
$query = "SELECT * FROM USERS WHERE userID = '$userID'";

$result = mysqli_query($link, $query) or die(mysql_errno());
$row = mysqli_fetch_assoc($result); 

 ?>

<div class="container">
<h1> <?php if(isset($_SESSION['username'])) { 
echo  $_SESSION['username'];
echo "'s Profile";
} ?>   
</h1>
<form class="form-horizontal" action="func/func_user_profile.php" method="post">
<div class="form-group">
    <label class="control-label col-sm-2"> Email:</label>
    <div class="col-sm-10">
        <input type="email" class="form-control" name="email" value="<?php echo $row["email"];?>">
    </div>
</div>
<div class="form-group">
    <label class="control-label col-sm-2"> Password:</label>
    <div class="col-sm-10">
        <input type="password" class="form-control" name="password" value="<?php echo $row["password"];?>">
    </div>
</div>
<div class="form-group">
    <label class="control-label col-sm-2"> Current monthly expenses:</label>
    <div class="col-sm-10">
        <input type="text" class="form-control" name="monthlyExpenses" value="<?php echo $row["monthlyExpenses"];?>">
    </div>
</div>


<div class="form-group" id="submit">
<input type="submit" class="btn btn-success" value="Update Profile" >
<input type="button" class="btn btn-danger" onClick="window.location.replace('welcome.php')" value="cancel">
</div>
</form>
 </div>


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


  </body>
  </html>

1 个答案:

答案 0 :(得分:0)

我测试了你的代码,它确实显示了数据库中的信息。 如果它没有显示任何内容,那应该是因为你的连接有问题。

<?php

 $userID = "1";
 $lastName = "Boo";
$server = "localhost";
$userName = "root";
$password = "";
$database = "test";




$conn =  mysqli_connect($server,$userName,$password , $database);
$query = "SELECT * FROM Boo WHERE userID = '$userID'";

$result = mysqli_query($conn, $query) or die(mysql_errno());
$row = mysqli_fetch_assoc($result); 

 ?>
<html>
<head>

</head>
<body>
<div class="container">
<h1> 
</h1>
<form class="form-horizontal" action="func/func_user_profile.php" method="post">
<div class="form-group">

    <label class="control-label col-sm-2"> Email:</label>
    <div class="col-sm-10">
        <input type="email" class="form-control" name="email" value="<?php echo $row["email"];?>">
    </div>
</div>
<div class="form-group">
    <label class="control-label col-sm-2"> Password:</label>
    <div class="col-sm-10">
        <input type="password" class="form-control" name="password" value="<?php echo $row["password"];?>">
    </div>
</div>


<div class="form-group" id="submit">
<input type="submit" class="btn btn-success" value="Update Profile" >
<input type="button" class="btn btn-danger" onClick="window.location.replace('welcome.php')" value="cancel">
</div>
</form>
 </div>




  </body>
  </html>

如果不同,请使用我使用过的连接。