Home  >  Article  >  Backend Development  >  How to modify sql in php

How to modify sql in php

藏色散人
藏色散人Original
2021-11-01 09:33:592269browse

How to modify sql in php: 1. Connect to the database and query the data; 2. Add data through the page addnews.html; 3. Through "mysql_query("UPDATE news SET title='$title'...) ” statement can be modified to update the data.

How to modify sql in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

How to modify sql in php?

PHP Mysql implements database addition, deletion, modification and query

PHP and Mysql can perform simple addition, deletion, modification and query on the database. This article introduces the news Backend management of the list.

Project address

https://github.com/caochangkui/php-mysql-test

Mysql database creation

Create A news list database:

How to modify sql in php

1. Query the database

1.1. Create the file dbconfig.php and save the constants

b5ad075cab544706ce672415c338989c  
100db36a723c770d327fc0aef2ce13b1  
30a2558f92eb013b60562303f10db00a  
    a80eb7cbb6fff8b0ff70bae37074b813  
    b2386ffb911b14667cb8f0f91ea547a7添加新闻6e916e0f7d1e588d4f442bf645aedb2f  
9c3bca370b5104690d9ef395f2c5f8d1
46d5fe1c7617e3914f214aaf043f4ccf
	form{
		margin: 20px;
	}
531ac245ce3e4fe3d50054a55f265927
6c04bd5ca3fcae76e30b72ad730ca86d
f183c3a2beadc0e1ede3a6cb9cfa78ef  
    2e1cf0710519d5598b1f0f14c36ba674标题:8c1ecd4bb896b2264e0711597d40766c9d4b1097ff533c07e208dfc2f023aaa5  
    2e1cf0710519d5598b1f0f14c36ba674关键字:8c1ecd4bb896b2264e0711597d40766c870e094f5f98782e56976fd61e1c399d  
    2e1cf0710519d5598b1f0f14c36ba674作者:8c1ecd4bb896b2264e0711597d40766c86a30740364efcfa938a43188642a31e  
    2e1cf0710519d5598b1f0f14c36ba674发布时间:8c1ecd4bb896b2264e0711597d40766cefcfc4015012ccd6635920d075859ba2  
    2e1cf0710519d5598b1f0f14c36ba674内容:8c1ecd4bb896b2264e0711597d40766c62c035209029b741eecb010365badbd5  
    10c88813b1d79313d0132c5ec3999828  
f5a47148e367a6035fd7a2faa965022e  
36cc49f0c466276486e50c850b7e4956  
73a6ac4ed44ffec12cee46588e518a5e

2.2 Create the server-side file action-addnews.php

c3dda597950a9768efafc66c462d468b
100db36a723c770d327fc0aef2ce13b1
93f0f5c25f18dab9d176bd4f6de5d30e
    a80eb7cbb6fff8b0ff70bae37074b813
    b2386ffb911b14667cb8f0f91ea547a7修改新闻6e916e0f7d1e588d4f442bf645aedb2f
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
bec4dc7c01d8d35dfeea446fb873ae74

5b6440b152f1717ad467bfa2d9f47bcc
    2e1cf0710519d5598b1f0f14c36ba674新闻ID: 8c1ecd4bb896b2264e0711597d40766c4be8a3545d89f1aff7be524582b95ff1">
    2e1cf0710519d5598b1f0f14c36ba674标题:8c1ecd4bb896b2264e0711597d40766c8c02f2ad7f2e96677eb4b5230248f28f">
    2e1cf0710519d5598b1f0f14c36ba674关键字:8c1ecd4bb896b2264e0711597d40766c2b3b94264a65f5319c5c21839ecfc82f">
    2e1cf0710519d5598b1f0f14c36ba674作者:8c1ecd4bb896b2264e0711597d40766c2af1655cc74b47cd711ef0965ca22e7e">
    2e1cf0710519d5598b1f0f14c36ba674发布时间:8c1ecd4bb896b2264e0711597d40766c32cc377d8d08043eec536521d39a9117">
    2e1cf0710519d5598b1f0f14c36ba674内容:8c1ecd4bb896b2264e0711597d40766ca2d9269dfb9a6f2cb53af92126c9c99d">
    10c88813b1d79313d0132c5ec3999828
f5a47148e367a6035fd7a2faa965022e

36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e

4.2 Modify through the server-side file action-editnews.php

Modify through the server-side file action-editnews.php [Recommended learning: "PHP Video Tutorial"]

<?php
// 处理编辑操作的页面 
require "dbconfig.php";
// 连接mysql
$link = @mysql_connect(HOST,USER,PASS) or die("提示:数据库连接失败!");
// 选择数据库
mysql_select_db(DBNAME,$link);
// 编码设置
mysql_set_charset('utf8',$link);

// 获取修改的新闻
$id = $_POST['id'];
$title = $_POST['title'];
$keywords = $_POST['keywords'];
$autor = $_POST['autor'];
$addtime = $_POST['addtime'];
$content = $_POST['content'];
// 更新数据
mysql_query("UPDATE news SET title='$title',keywords='$keywords',autor='$autor',addtime='$addtime',content='$content' WHERE id=$id",$link) or die('修改数据出错:'.mysql_error()); 
header("Location:demo.php");

The above is the detailed content of How to modify sql 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