// 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) ); *' |