您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

一个简单的自动发送邮件系统(二)_PHP教程

2024/3/13 7:06:06发布31次查看
这里介绍php和mysql结合起来实用。
基本上,可以说php是介于后台数据库和前台浏览器的一个中间层,在他们之间传递命令。这种方式大大提高了交互的可能性,可以方便使用在投票系统,其他动态用户输入和个性化网站中。
要想实现这种交互,首先必需实现和mysql数据库连接,可以使用这个命令实现:
    语法:int mysql_connect(string hostname, string username, string password);
·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) );
----------------------------
现在让我们假设我们要吧用户的信息插入到这个数据库中,我们可以通过修改email.php3脚本来实现,修改如下:
----------------------------
/* 这个脚本将使用从moreinfo.html文件中传递过来的变量。 */
/* 声明一些相关的变量 */
$hostname = devshed;
$username = myusername;
$password = mypassword;
$dbname = mydbname;
/* 使用mysql建立的数据表存取信息  */
$userstable = information;
/* 网站管理员的邮件地址*/
$adminaddress = administration@buycorn.com;
/* 与数据库连接*/
mysql_connect($hostname,$username,$password) or die(unable to connect to database);
@mysql_select_db($dbname) or die(unable to select database);
print
;
print hello, $name.;
print
;
print thank you for your interest.
;
print we will send information to $email, and have noted that you like $preference;
print
;
/* 发送有关邮件*/
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.);
/* 将数据插入数据表中*/
$query = insert into $userstable values('$name','$email', '$preference');
$result = mysql_query($query);
print your information has also been inserted into our database, for future reference.;
/* 关闭与数据库的连接*/
mysql_close();
?>
----------------------------
一些注意的地方:
1、在脚本一开始声明的变量是为了函数mysql_connect() 。我们也可以直接在函数中将这些值给出,可是,考虑工程的可发展性,这些值应该放在一个独立的文件中,用(#include)调入。
2、语法: int mysql_select_db(string database_name, int link_identifier);
·database_name  必需是在服务器上的数据库名。
·link_identifier(可选的) 是指明连接,基于此向数据库服务器发出请求。
·返回值为true/false
3、语法: int mysql_query(string query, int link_identifier);
·query  发送向mysql服务器的sql命令。
·link_identifier(可选择)  指明连接,基于此向数据库服务器发送sql命令。
·返回值为整数,正数表示成功了,负数表示失败。
4、语法: int mysql_close(int link_identifier);  
·link_indentifier  与上面相同
·返回值为整数,正数表示成功了,负数表示失败。
在下一篇文章中,我将给大家讲解如何从mysql中输出数据。 
http://www.bkjia.com/phpjc/315419.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/315419.htmltecharticle这里介绍php和mysql结合起来实用。 基本上,可以说php是介于后台数据库和前台浏览器的一个中间层,在他们之间传递命令。这种方式大大提...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product