Php Getting Started Tutorial: saving, deleting, modifying, updating, and querying php mysql data

Source: Internet
Author: User
Tags php mysql

*/

The code is as follows: Copy code

// Connect to and select a database
$ Conn = mysql_connect ("localhost", "phpdb", "phpdb ")
Or die ("cannot connect to the database server:". mysql_error ());
Mysql_select_db ("test", $ conn) or die ("The database cannot be selected:". mysql_error ());
// Insert record
// Edit the SQL statement for inserting records
$ Insertsql = "insert into user (name, password, address, tel, email) values ('Wang Qiang ', '123', 'Shenzhen', '123 ', 'Wang @ wel.com ')";
// Execute the insert operation
$ Insert = mysql_query ($ insertsql, $ conn );
// Check whether the insert operation is successful
If ($ insert ){
Echo "insert record successful! ";
Echo "<br> ";
}
Else
{
Echo "an error occurred while inserting the record! ";
Echo "<br> ";
}

// Modify the record
// Edit the SQL statement of the modification record
$ Updatesql = "update set tel = '000000' from user where name = 'Wang Qiang '";
// Perform the modification operation
$ Update = mysql_query ($ updatesql, $ conn );
// Check whether the modification operation is successful
If ($ update ){
Echo "the record has been modified! ";
Echo "<br> ";
}
Else
{
Echo "an error occurred while modifying the record! ";
Echo "<br> ";
}

// Delete the record
// Edit the SQL statement for deleting a record
$ Deletesql = "delete from user where name = 'Wang Qiang '";
// Perform the delete operation
$ Delete = mysql_query ($ deletesql, $ conn );
// Check whether the deletion operation is successful
If ($ delete ){
Echo "records deleted! ";
Echo "<br> ";
}
Else
{
Echo "an error occurred while deleting the record! ";
Echo "<br> ";
}

/*
Use test;
Create table users (
Id int (3) not null auto_increment,
Name varchar (20) not null,
Password varchar (50) not null,
Address varchar (50 ),
Tel varchar (20 ),
Email varchar (50) not null,
Primary key (id)
);
*'

?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.