Write blogs-php & amp; MySQL practices, and write blogs-php. Squeeze time to write a blog-phpMySQL practice, write a blog-phphi should eat hot pot at night, squeeze time to write something, don't be discovered by the boss. 1. PHP and MySQL. 5. after the article is published, enter the blog-php & MySQL practices, and write the blog-php.
Hi
If you want to eat hot pot at night, just take some time to write something. Don't be discovered by the boss.
1. PHP and MySQL
V. Post-article publishing system
5.2 Create a configuration file and an initialization file
To simplify configuration and management, we also need to reduce code redundancy.
Config. php and connect. php
Config. php
/*
* Configuration file
*/
// Configure database information
// Directly use define because it is a constant
Define ('host', '2017. 0.0.1 ');
Define ('username', 'root ');
Define ('password ','');
Connect. php
/*
* Files linked to the database
* Link to the database server and select the database.
* Set character sets.
* You want to determine each operation.
*/
// Contains the configuration file
Require_once 'config. php ';
// Database connection
If (! $ Con = mysqli_connect (HOST, USERNAME, PASSWORD )){
Echo mysqli_error ($ con );
}
// Select a database
If (mysqli_select_db ($ con, 'info ')){
Echo mysqli_error ($ con );
}
// Character set
If (mysqli_query ($ con, 'set names utf8 ')){
Echo mysqli_error ($ con );
}
Then, test the link file. Both mysql and mysqli can be used here, as long as the format is correct.
5.3 publish an article
Article publishing interface article. add. php
Untitled Document
Background management system |
Publish an article Manage articles |
|
Copyright |
It's not very beautiful. just study.
Article publishing handler article. add. handle. php
Require_once ('../connect. php ');
// Store the passed information into the database and verify all the information before receiving the data.
If (! (Isset ($ _ POST ['title']) & (! Empty ($ _ POST ['title']) {
Echo "script" alert ('title cannot be blank '); 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 ('post succeeded '); window. location. href = 'article. manage. php'; script ";
} Else {
Echo "script" alert ('publishing failed'); window. location. href = 'article. manage. php'; script ";
}
?>
Note the functions and connections between the two, that is, the add page transmits things to handle for processing.
------------------------
Because I have encountered unseen garbled code problems... Kneeling to solve .... Hope you don't give me some advice (wamp environment, mysql, zend, the browser has been set to utf8, apache configuration file added adddefacharcharset UTF-8, the problem still exists, I dizzy ah ....)
Hi, I want to eat hot pot at night. squeeze some time to write something. Don't be noticed by the boss. 1. PHP and MySQL. 5. set up the system after the article is published...