Php code _ PHP Tutorial for adding records to the database

Source: Internet
Author: User
Add the recorded php code to the database. Php code for adding records to the database this is a simple use of phpmysql to save user submitted information to the database instance. copy the file below to your dw and you will be able to use it. The php code used to add records to the database is a simple php mysql code that saves user submitted information to the database instance. copy the file below to your dw and you will be able to use it.

Add recorded php Tutorial code for database tutorials
This is a simple php mysql tutorial that saves the information submitted by the user to the database instance. copy the file below to your dw and you will be able to use it.
*/

If ($ _ post)
{
$ Host = 'localhost ';
$ User_name = 'root ';
$ Password = 'admin ';

$ Name = $ _ post ['User _ name'];
$ City = $ _ post ['city'];

If (empty ($ name) | trim ($ name) = '')
{
Echo 'Enter the user name! Return ';
Exit;
}

$ Conn = mysql_connect ($ host, $ user_name, $ password );
If (! $ Conn)
{
Die ('database connection failed: '. mysql_error ());
}
Mysql_select_db ('test ');

$ SQL = "insert into users set id = 7, name = '". $ name. "', city = '". $ city. "', created_time = now ()";
Mysql_query ($ SQL) or die ("
Error: ". Mysql_error ()."
SQL: ". $ SQL );
Mysql_close ($ conn );

Echo 'data inserted successfully, open view data ';
}

?>
Submit user information

Mysql saves the information submitted by the user to the database instance. copy the file below to your dw. Database tutorial...

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.