For friends who are learning php, they started to make a message board and had a simple process for php + mysql operations. I learned this and started to get started with php.
Config. php
The code is as follows:
$ Conn = @ mysql_connect ("localhost", "root", "") or die ("database connection error! ");
Mysql_select_db ("gb", $ conn );
Mysql_query ("set names 'gbk '");
?>
Add. php
The code is as follows:
Include ("config. php ");
If ($ _ POST ['submit ']) {
// In this case, the lastdate field in the message is not written, causing data insertion to fail. It takes a long time to locate the error.
$ SQL = "insert into message (id, user, title, content, lastdate) values ('', '$ _ POST [user]', '$ _ POST [title]', '$ _ POST [content]', now ())";
Mysql_query ($ SQL );
Echo "successful ";
}
?>
View. php
The code is as follows:
Include ("config. php ");
?>
$ SQL = "select * from message order by id desc ";$ Query = mysql_query ($ SQL );While ($ row = mysql_fetch_array ($ query )){?>// NND. In the wampserver default environment This syntax means that no content can be read. You must use this method. Depressed. It took a long time to figure it out.
Title: User: |
Content: |
}?>
Then there is a database SQL.
The code is as follows:
Create table 'message '(
'Id' tinyint (1) not null auto_increment,
'User' varchar (25) not null,
'Title' varchar (50) not null,
'Content' tinytext not null,
'Lastdate' date not null,
Primary key ('id ')
) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;