php修改sql的方法:1、连接数据库并查询数据;2、通过页面addnews.html添加数据;3、通过“mysql_query("UPDATE news SET title='$title'...)”语句修改更新数据即可。
本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑
php 怎么修改sql?
PHP+Mysql 实现数据库增删改查
PHP和Mysql可以对数据库进行简单的增删改查,本文介绍了新闻列表的后台管理。
https://github.com/caochangkui/php-mysql-test
创建一个新闻列表的数据库:
e44eb1708a2c7f162566ec00268042a9 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
117dc0c222bae75f0843ad64eef92c3a 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
通过服务端文件action-editnews.php进行修改处理【推荐学习:《PHP视频教程》】
<?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");
以上是php 怎么修改sql的详细内容。更多信息请关注PHP中文网其他相关文章!