How to use the background to publish an article and display it on the foreground

Source: Internet
Author: User
How to use the background to publish an article and display it on the foreground. Every time you manually write code & nbsp; on the front end to add an article, it is very troublesome and tiring. I want to write a function in the background and enter the title, Content & nbsp; to publish it directly. & Nbsp; I want to read files. Then, use regular expressions to read a location of the PHP file and add an article. for example, I want to use the background to publish an article and display it on the foreground.
Every time you manually write code on the front end to add an article, it is very troublesome and tiring. I want to write a function in the background, enter the title, and the content can be published directly. I want to use the file to read. Then, use regular expressions to read a location of the PHP file and add an article, such
I want to display an article in index. php. The content of index. php is

Author -------------- article title ------------- article time



Black-Hole

PHP code


February 28, 2014



I will first write a title content author time in the background. After you click Publish, write a regular expression to read the articles in index. php> and. Erase the content and write it to the author time of the title content I just wrote.

This ensures that new posts are always the first. This saves the trouble of manually writing code to add articles.

I learned php for less than one year. So I don't know much about it. I hope you guys will take care of new people. thank you.
------ Solution --------------------
This is a basic thing.
You can view the dbconnect, select, insert, update, and delete syntaxes of mysql.
I wrote a demo, which can be inserted into the database and display records in reverse chronological order of the database. I hope this will help you.

Dbname is demo

Connect to database
$ Conn = @ mysql_connect ("localhost", "root", "") or die (mysql_error ());
@ Mysql_select_db ('demo', $ conn) or die (mysql_error ());

Localhost is the server ip address.
Root is the database user name
The password is empty.

Db structure

CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `age` tinyint(4) unsigned NOT NULL,
  `addtime` datetime NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


Db. php is used to display Records


// Open the database
Function opendb (){
$ Conn = @ mysql_connect ("localhost", "root", "") or die (mysql_error ());
@ Mysql_select_db ('demo', $ conn) or die (mysql_error ());
}

// Close the database
Function closedb (){
@ Mysql_close () or die ("The parameter number is disconnected! ");
}

Opendb ();

Echo' ';

$ Sqlstr = "select * from test order by addtime desc ";
$ Query = mysql_query ($ sqlstr) or die (mysql_error ());

While ($ thread = mysql_fetch_assoc ($ query )){
$ Result [] = $ thread;
}

If ($ result ){
Foreach ($ result as $ val ){
Echo $ val ['id']. ''. $ val ['name']. ''. $ val ['age']. ''. $ val ['addtime'].'
';
}
}

?>


Add. php is used to add Records


// Open the database
Function opendb (){
$ Conn = @ mysql_connect ("localhost", "root", "") or die (mysql_error ());
@ Mysql_select_db ('demo', $ conn) or die (mysql_error ());
}

// Close the database
Function closedb (){
@ Mysql_close () or die ("The parameter number is disconnected! ");
}

Opendb ();


$ Send = isset ($ _ POST ['send'])? $ _ POST ['send']: '';

If ($ send = 'true') {// submit

$ Name = isset ($ _ POST ['name'])? $ _ POST ['name']: '';
$ Age = isset ($ _ POST ['age'])? $ _ POST ['age']: '';
$ Addtime = date ('Y-m-d H: I: s ');

If ($ name =''
------ Solution --------------------
$ Age = ''){
Exit ('name or age is empty ');
}

$ Sqlstr = "insert into test (name, age, addtime) values ('{$ name}', '{$ age}', '{$ addtime }')";
Mysql_query ($ sqlstr) or die (mysql_error ());

Echo 'Insert success ';

} Else {

?>


 

New Document

 

 

Name:


Age:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.