Home  >  Article  >  Backend Development  >  PHP and MySQL - modify records

PHP and MySQL - modify records

巴扎黑
巴扎黑Original
2016-11-30 09:31:151338browse

<h1>修改记录</h1>
<?php
if(isset($_POST[&#39;btnModify&#39;])){
//验证表单省略
$sql = "UPDATE animal SET WHERE ID = &#39;$_POST[id]&#39;";
$result = mysqli_query($sql);//执行更新
if($result){
echo "修改已经成功!";
}
else
{
echo "修改失败!";
}
}
//查询当前的记录
$query = "SELECT * FROM symbols";
//执行该查询
if($result = $mysqli->query($query)){
//显示返回的记录集行数
if($result->num_rows>0){
//如果有记录
//显示记录集中列的内容
echo "<table cellpadding=10 border=1>";
while($row=$result->fetch_array()){
echo "<tr>";
echo "<td><input name=&#39;id&#39; type=&#39;text&#39; id=&#39;id&#39; value=&#39;$row[0]&#39;/></td>";
echo "<td><input name=&#39;country&#39; type=&#39;text&#39; id=&#39;country&#39; value=&#39;$row[1]&#39;/></td>";
echo "<td><input name=&#39;animal&#39; type=&#39;text&#39; id=&#39;animal&#39; value=&#39;$row[2]&#39; /></td>";
echo "<td><input name=&#39;btnModify&#39; type=&#39;submit&#39; id=&#39;btnModify&#39; value=&#39;修改&#39; /></td>";
echo "</tr>";
}
}
//释放对象所占用的内存
$result->close();
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn