这是我的代码,我需要帮助
我需要从数据库中获取数据,然后将其放入表单中,在表单之后我需要能够更改放入表单中的信息,然后才能更新它
<?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>
答案 0 :(得分:0)
首先请阅读如何构建和执行查询。
http://php.net/manual/en/pdo.prepare.php
然后,我建议只在一个查询中获取所有这些数据:
&#34; SELECT * FROM artist WHERE ID =:id&#34;