Home > Backend Development > PHP Tutorial > Squeeze some time to blog-php&MySQL practice, blog-php_PHP tutorial

Squeeze some time to blog-php&MySQL practice, blog-php_PHP tutorial

WBOY
Release: 2016-07-12 09:03:56
Original
713 people have browsed it

Squeeze some time to blog-php&MySQL practice, blog-php

 hi

You’re going to have hot pot tonight, take some time to write something, don’t let your boss find out

1. PHP and MySQL

5. Backend of article publishing system

5.2 Create configuration file and initialization file

In order to unify the configuration and facilitate management, there is also the need to reduce code redundancy.

Config.php and connect.php respectively

config.php

/*
* Configuration file
*/
//Configuration database related information
//Since it is a constant, use define
define( 'HOST', '127.0.0.1');
define('USERNAME', 'root');
define('PASSWORD', '');

connect.php

/*
* File linked to the database
* Mainly link to the database server and then select the database.
* The special thing is to set the character set.
* Then hope to judge each operation
*/

//Include configuration file
require_once 'config.php';

//Connect the database
if(!$con=mysqli_connect(HOST,USERNAME,PASSWORD)){
echo mysqli_error($con);
}

//Select database
if(mysqli_select_db($con, 'info')){
echo mysqli_error($con);
}

//Character set
if(mysqli_query($con,'set names utf8')){
echo mysqli_error($con);
}

After completion, test the linked file and it will be ok. Both mysqli and mysql are acceptable here, as long as the format is correct.

5.3 Publish article

Article publishing interface article.add.php





Untitled document

< /head>













后台管理系统

发布文章


管理文章


























发布文章
标题
作者
简介
内容

版权所有


不是很漂亮就是了,学习嘛

 

文章发布处理程序article.add.handle.php

require_once('../connect.php');
//把传递过来的信息入库,在入库之前对所有的信息进行校验。
if(!(isset($_POST['title'])&&(!empty($_POST['title'])))){
echo "<script>alert('标题不能为空');window.location.href='article.add.php';</script>";
}
$title = $_POST['title'];
$author = $_POST['author'];
$description = $_POST['description'];
$content = $_POST['content'];
$dateline = time();
$insertsql = "insert into article(title, author, description, content, dateline) values('$title', '$author', '$description', '$content', $dateline)";
if(mysqli_query($con,$insertsql)){
echo "<script>alert('发布文章成功');window.location.href='article.manage.php';</script>";
}else{
echo "<script>alert('发布失败');window.location.href='article.manage.php';</script>";
}
?>

注意两者的功能和连接,就是add页面把东西传给handle处理

 ------------------------

由于我遇到了前所未见的乱码问题。。。跪着解决中。。。。望大家不吝赐教(wamp环境,mysql,zend,浏览器都已经设置为utf8,apache配置文件中添加了AddDefaultCharset UTF-8,问题依然存在,我晕啊。。。。)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1077133.htmlTechArticleSqueeze some time to blog-phpMySQL practice, blog-php hi If you want to eat hot pot in the evening, squeeze some time Write something, don’t be discovered by the boss 1. PHP and MySQL 5. Article publishing system backend...
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