使用HTML表单编辑MySQL重新编码 [英] Editing MySQL recode using a HTML form
本文介绍了使用HTML表单编辑MySQL重新编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从事一个小型PHP项目,以进行学习.我想从MySQL数据库中检索保存的数据,并让用户使用HTML表单对其进行编辑.我无法检索数据并显示在文本框中.问题是提交表单时数据没有更新.这是我到目前为止得到的代码.进行文件自我更新.如果有人可以告诉我我在哪里出错了,将不胜感激.谢谢.
Im working on a small PHP project for learning purpose. i want to retrieve saved data from a MySQL data base and let the user edit it using a HTML form. im able to retrieve the data and display in the text boxes. problem is when the form is submitted data is not updating. here is the code i got so far. file is made to update it self. if anyone can tell me where did i go wrong it will be most appreciated. thank you.
<?php
include ("header.php");
include ("../db.php");
$catname = $_POST['catname'];
$catdisc = $_POST['catdisc'];
$id = $_GET['id'];
if (isset($id))
{
$query = "SELECT * FROM categories WHERE catid='$id'";
$result= mysql_query($query) or die ('Mysql Error');
}
while($row = mysql_fetch_array($result)){
$cname = $row['catname'];
$cdisc = $row['catdisc'];
}
$result= "UPDATE categories SET catname='$catname', catdisc='$catdisc' WHERE catid='$id'"
or die ('Error Updating');
?>
<h1>Edit Categories</h1>
<form method="post" action="edit_cat.php?id=<?php echo $id;?>">
Category Name: <input type="text" name="catname" value="<?php echo $cname;?>"><br/>
Category Discription: <TEXTAREA NAME="catdisc"ROWS="3" COLS="25"><?php echo $cdisc;?></TEXTAREA><br/><br/>
<input type="submit" value="Update Category"/>
</form>
<?php
include ("footer.php");
?>
推荐答案
$result= mysql_query("UPDATE categories SET catname='$catname', catdisc='$catdisc' WHERE catid='$id'") or die ('Error Updating');
这篇关于使用HTML表单编辑MySQL重新编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文