How does PHP write data to the MySQL database using SQL statements?

Source: Internet
Author: User
Tags md5 encryption php and mysql php write

1,php and MySQL establish a connection relationship

2, open

3, accept the page data, PHP input into the specified table

1, 22 step can directly use a database link file: conn.php


<?php
mysql_connect ("localhost", "root", "");//Connect MySQL
mysql_select_db ("Hello");//Select Database
?>

Of course, the premise is that the Web server, PHP and MySQL are installed, and the MySQL table "WEBJX" is built

Mysql_connect () Three parameters are MySQL address, MySQL user name and MySQL password, respectively


Then the data is passed through the Web page, allowing PHP to write data to the table specified in the MySQL database via SQL statements, such as a new file post.php


<?php
Require_once ("conn.php");//reference Database link file

$uname = $_get[' n '];//get method passed for URL parameter
$PSW = $_get[' P '];
$PSW =md5 ($PSW);//use MD5 encryption directly

$sql = "INSERT INTO members (Username,password) VALUES (' $uname ', ' $psw ')";
mysql_query ($sql);//Use SQL statements to insert data

Mysql_close ();//close MySQL connection
echo "successfully entered data";
?>


You can insert the new data "WEBJX" to the username field, "i0514" to the password field from the members table of the MySQL database hello

Dual L5520 4*1t RAID 64G 10M 128ip Special 2000 yuan/month database dedicated. Lao Zhang Qq:2881064151

How does PHP write data to the MySQL database using SQL statements?

Related Article

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.