Home > Backend Development > PHP Problem > How to modify records in php mysql

How to modify records in php mysql

藏色散人
Release: 2023-03-12 10:30:02
Original
2300 people have browsed it

php Mysql method to modify records: 1. Query the current record through "SELECT * FROM symbols"; 2. Modify the record through "mysqli_query($sql);".

How to modify records in php mysql

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php How to modify mysql records?

The example in this article describes how to modify records in PHP MySQL. Share it with everyone for your reference.

The details are as follows:

The code is as follows:

<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(); 
    } 
?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to modify records in php mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template