一 代码
conn.php
<?php $conn = mysql_connect("localhost","root","root") or die("数据库错误".mysql_error()); mysql_select_db("db_database21",$conn) or die("数据库错误".mysql_error()); mysql_query("set names gb2312"); ?>
index.php
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>使用md5对用户注册密码进行加密</title> <style type="text/css"> <!-- body,td,th { font-size: 12px; } body { margin-left: 10px; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; } .STYLE1 { font-size: 14px; font-weight: bold; } --> </style> </head> <body> <table width="777" height="587" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.jpg"> <tr> <td width="149" height="200"> </td> <td width="448"> </td> <td width="158"> </td> </tr> <tr> <td height="187"> </td> <td align="center" valign="middle"> <form id="form1" name="form1" method="post" action="index_ok.php"> <table height="160" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="83" height="30" align="right" valign="middle" scope="col"><span class="STYLE1">用户名:</span></td> <td width="267" height="30" align="left" valign="middle" scope="col"><label for="textfield"></label> <input name="username" type="text" id="username" size="24" /></td> <td width="25" align="center" valign="middle" scope="col"> </td> </tr> <tr> <td height="30" align="right" valign="middle" class="STYLE1" scope="col">密码:</td> <td height="30" align="left" valign="middle" scope="col"><input name="password" type="password" id="password" size="25" /></td> <td align="center" valign="middle" scope="col"> </td> </tr> <tr> <td height="30" align="right" valign="middle" class="STYLE1" scope="col">地址:</td> <td height="30" align="left" valign="middle" scope="col"><input name="address" type="text" id="address" size="35" /></td> <td align="center" valign="middle" scope="col"> </td> </tr> <tr> <td height="30" align="right" valign="middle" class="STYLE1" scope="col">电话:</td> <td height="30" align="left" valign="middle" scope="col"><input name="tel" type="text" id="tel" size="20" /></td> <td align="center" valign="middle" scope="col"> </td> </tr> <tr> <td height="40" colspan="3" align="center" valign="middle" scope="col"><input type="image" name="imageField" src="images/bg2.JPG" /> <input type="image" name="imageField2" src="images/bg1.JPG" onclick="form.reset();return false;" /></td> </tr> </table> </form> </td> <td> </td> </tr> <tr> <td height="200"> </td> <td> </td> <td> </td> </tr> </table> </body> </html>
index_ok.php
<?php include("conn/conn.php"); if(trim($_POST[username])!= "" and trim($_POST[password])!= "" and trim($_POST[tel])!=""){ $pwd = md5($_POST[password]); $sql = "insert into tb_user(username,password,address,explains)values('".$_POST[username]."','".$pwd."','".$_POST[address]."','".$_POST[tel]."')"; $result = mysql_query($sql,$conn); if($result){ echo "<font color='red'>注册成功。</font>"; }else{ echo "<font color='green'>注册失败!</font>"; } }else{ echo "请认真填写用户名和密码!"; } ?>
二 运行结果
注册成功。
数据库数据如下: