·hostname - 运行数据库服务器所在的主机名称。 ·username - 连接到数据库服务器的用户名称。 ·password - 用户密码。the password set to connect to the mysql database. 如果连接成功,函数返回一个正整数,如果失败返回一个负数。
所有的命令,和往常一样,必需放置在"<?" 和 "?>"之间。
让我们继续我们的工程,让我们假设用mysql建立了以下的数据表:
----------------------------
mysql> create table information ( -> name varchar (25), -> email varchar (25), -> choice varchar (8) );
/* 与数据库连接*/ mysql_connect($hostname,$username,$password) or die("unable to connect to database");
@mysql_select_db("$dbname") or die("unable to select database");
print "<center>"; print "hello, $name."; print "<br><br>"; print "thank you for your interest.<br><br>"; print "we will send information to $email, and have noted that you like $preference"; print "</center><br><br>";
/* 发送有关邮件*/ mail("$email", "your request for information", "$namenthank you for your interest!n we sell fresh corn daily over the internet! place your order at http://www.buycorn.com, and receive a free package of $preference!");
mail("$adminaddress", "visitor request for info.", "$name requested for information.n
the email address is $email. n the visitor prefers $preference.");