【问题标题】:How to select specific data from database and put it into a HTML form with update?如何从数据库中选择特定数据并将其放入带有更新的 HTML 表单中?
【发布时间】:2017-01-31 06:35:14
【问题描述】:

这是我的代码,我需要帮助

我需要从数据库中获取数据然后输入到表单中,在表单之后我需要能够更改输入到表单中的信息然后能够更新它

<?php
print_r($_REQUEST);


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "artiest";

$dbh = new PDO('mysql:host=localhost;dbname=artiest', $username,$password);
$id = $dbh->lastInsertId();


$name = $dbh->SELECT name FROM artist WHERE ID = $id;
$email = $dbh->SELECT email FROM artist WHERE ID = $id;
$gender = $dbh->SELECT gender FROM artist WHERE ID = $id;
$comment = $dbh->SELECT comment FROM artist WHERE ID = $id;
$website = $dbh->SELECT website FROM artist WHERE ID = $id;

$dbh = null;
?>


<h2>Artiest Wijzigen</h2>

<form method="post" action="add_artist.php">  
 Naam: <input type="text" name="name" value="<?php echo $name;?>">

<br><br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">

<br><br>
Website, artiest: <input type="text" name="website" value="<?php echo $website;?>">

<br><br>
Extra toevoegingen:<br> <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
<br><br>
Geslacht:
<input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Vrouw
<input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Man

 <br><br>
 <input type="submit" name="submit" value="Veranderen">  
 </form>

【问题讨论】:

  • 很好。那么你的问题是什么?
  • 顺便说一句,您的 SELECT 都会给您带来错误。但我认为这可能是伪代码。
  • 我的问题是,我不是 php 的专业人士,我正在尝试学习它,如何使这段代码工作,我不是专家@PatrickQ

标签: php html mysql forms pdo


【解决方案1】:

首先请阅读如何构建和执行查询。

http://php.net/manual/en/pdo.prepare.php

然后,我建议在一个查询中获取所有这些数据:

"SELECT * FROM Artist WHERE ID = :id"

【讨论】:

    猜你喜欢
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 2015-07-10
    • 2015-09-22
    相关资源
    最近更新 更多