Home > Backend Development > PHP Problem > How to modify database content in php

How to modify database content in php

藏色散人
Release: 2023-03-05 09:52:02
Original
4819 people have browsed it

php method to modify database content: first select the database; then obtain the data set through the "mysql_query($q)" statement; then read the data in a loop and store it in the array object; finally modify the database field content through the UPDATE method That’s it.

How to modify database content in php

Recommendation: "PHP Video Tutorial"

php front-end passes parameters, traverses the fields of the database table according to the conditions to modify.

<?php
    header("Content-Type:text/html;charset=utf8"); 
    header("Access-Control-Allow-Origin: *"); //解决跨域
    header(&#39;Access-Control-Allow-Methods:POST&#39;);// 响应类型  
    header(&#39;Access-Control-Allow-Headers:*&#39;); // 响应头设置 
    $link=mysql_connect("localhost","root","root"); 
    mysql_select_db("business_card", $link); //选择数据库
    mysql_query("SET NAMES utf8");//解决中文乱码问题
    $wx_id = $_POST[&#39;wx_id&#39;];
    $openid = $_POST[&#39;openid&#39;];
    $q = "SELECT * FROM user"; //SQL查询语句 SELECT * FROM 表名
    $rs = mysql_query($q); //获取数据集
    if(!$rs){die("数据库没有数据!");}
//循环读取数据并存入数组对象
    $dlogs;$i=1;
    while($row=mysql_fetch_array($rs))
    {
$result = @mysql_query($strsql);
        if($row["openid"]==$openid){
if($row["collect"]!=""){
$ab =$row["collect"].&#39;,&#39;.$wx_id;
}else{
$ab =$wx_id;
}
//修改数据库字段
mysql_query("UPDATE user SET collect = &#39;$ab&#39;
WHERE openid = &#39;$openid&#39;");
 
    echo urldecode(json_encode($ab));
}
    }
    //以json格式返回html页面
   
    
?>
Copy after login

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

Related labels:
php
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