私はウェブデザイナーですが、開発を進めていますので、データベースのデータを表示する動的フォームを作成しましたが、提供されているフォームコードを使用して更新する必要があります。PHPを使用してデータベースを更新するには?
誰でもこのフォームをコード化することができれば、私は感謝します。
私が書いた完全なコードは次のとおりです。
<?php
include("db/db.php");
if(isset($_GET['edit'])){
$edit_id = $_GET['edit'];
$edit_query = "select * from article where ID='$edit_id'";
$run_edit = mysql_query($edit_query);
while ($edit_row=mysql_fetch_array($run_edit)){
$post_id = $edit_row['ID'];
$post_title = $edit_row['title'];
$post_author = $edit_row['author'];
$post_keywords = $edit_row['keywords'];
$post_image = $edit_row['image'];
$post_content = $edit_row['content'];
}
}
?>
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Update the Article</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form method="post" action="edit_posts.php?edit_form=<?php echo $edit_id; ?>" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<label >Post Title</label>
<input type="text" class="form-control" name="title" size="30" value="<?php echo $post_title; ?>">
</div>
<div class="form-group">
<label >Post Author</label>
<input type="text" class="form-control" name="author" value="<?php echo $post_author; ?>">
</div>
<div class="form-group">
<label >Post Keywords</label>
<input type="text" class="form-control" name="keywords" value="<?php echo $post_keywords; ?>">
</div>
<div class="form-group">
<label for="exampleInputFile">Post Image</label>
<input type="file" name="image" value="<?php echo $post_image; ?>" id="exampleInputFile">
<img src="../img/news/<?php echo $post_image;?>" width="50" height="50"/>
</div>
<div class="form-group">
<label >Post Keywords</label><br>
<textarea name="content" class="form-control" rows="15" ><?php echo $post_content; ?></textarea>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary">Update</button>
</div>
</form>
</div>
このコードは、入力値に完全にデータベースからデータを表示しますが、私はこのフォームからデータベースを更新する方法を支援する必要があります。あなたのedit_posts.php
で
SQLインジェクション攻撃にオープン –
そこには多くのチュートリアルがあります。外出して自分で試してください。あなたはこれを自分自身で達成することから、さらに多くを得るでしょう。 Stack Overflowは、特定の質問をする場所であり、人々にコードを書くような場所ではありません。 – iblamefish
私はたくさんのツイートをしようとしましたが、このフォームやコードではうまくいきませんでした。 –