I use the following codes to insert data into the database, the database name is "mydata",the table name is "customers", the table has 4 fields which are CustID,CustName,Email and Address. I think these codes are not laconic enough,how to simplify them while keeping their function.
| Code: |
| <?php
$cn=mysql_connect('localhost','root','333333') or die("Fail to connect!"); $strsql1="insert into customers (CustID,CustName,Email,Address) values ('C00001','Bart','liuxl@souhu.com','myhome')"; $strsql2="insert into customers (CustID,CustName,Email,Address) values ('C00002','Marry','wangdh@263.net','xxxxxxxxx')"; $strsql3="insert into customers (CustID,CustName,Email,Address) values ('C00003','Goedo','zhangww@pa18.com','xxxxxx')"; $strsql4="insert into customers (CustID,CustName,Email,Address) values ('C00004','Lizzie','linwd@sina.com','xxxxxxx')"; $strsql5="insert into customers (CustID,CustName,Email,Address) values ('C00005','Miranda','xiexl@sohu.com','xxxxxx')"; mysql_db_query("mydata",$strsql1,$cn); mysql_db_query("mydata",$strsql2,$cn); mysql_db_query("mydata",$strsql3,$cn); mysql_db_query("mydata",$strsql4,$cn); mysql_db_query("mydata",$strsql5,$cn); mysql_close($cn); ?> |
