Home  >  Article  >  Backend Development  >  How to modify database content in php

How to modify database content in php

藏色散人
藏色散人Original
2020-08-27 09:45:374742browse

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页面
   
    
?>

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!

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