简易通讯录

<?php error_reporting(0); ?>
<!--***************************-->
<html>
<head>
<title>简易通讯录添加记录前台</title>
</head>

<body>
<script language="javascript">
function Juge(theForm)
{
    if(theForm.name.value=="")
    {
        alert("请输入姓名!");
        theForm.name.focus();
        return(false);
    }
    
        if(theForm.mail.value=="")
    {
        alert("请输入邮箱!");
        theForm.mail.focus();
        return(false);
    }
    
    
        if(theForm.phone.value=="")
    {
        alert("请输入电话号码!");
        theForm.phone.focus();
        return(false);
    }
        if(theForm.address.value=="")
    {
        alert("请输入地址!");
        theForm.address.focus();
        return(false);
    }
}
</script>

<center>
<h1>简易通讯录添加记录前台</h1>
<p>
<a href="index.php">返回首页</a>
<table border=1>
<form action="index1.php" method="post" onsubmit="return Juge(this)">
<tr>
<td>输入姓名:</td>
<td><input name="name" type="text"></td>
</tr>

<tr>
<td>输入邮箱:</td>
<td><input name="mail" type="text"></td>
</tr>

<tr>
<td>输入电话:</td>
<td><input name="phone" type="text"></td>
</tr>


<tr>
<td>输入姓名:</td>
<td><input name="address" type="text"></td>
</tr>


<tr>
<td colspan="2"><center><input type="submit" value="确认提交">
<input type="reset" value="重新选择"></center></td>
</tr>
</form>
</table>
</p>
</center>
</body>
</html>


<!--***********以上是前台页面***************-->

 

<!--***********下面是数据处理页面***************-->

<?php error_reporting(0); ?>
<?php
$name=htmlspecialchars($_POST['name']);
$mail=htmlspecialchars($_POST['mail']);
$phone=htmlspecialchars($_POST['phone']);
$address=htmlspecialchars($_POST['address']);

$db_host="localhost";
$db_user="root";
$db_pass="";
$db_name="test";
$table_name="test1";

$myconn=mysql_connect("$db_host","$db_user","$db_pass");
mysql_select_db("$db_name",$myconn);
$strSql="insert into $table_name(name,mail,phone,address)values('$name','$mail','$phone','$address')";

mysql_query($strSql,$myconn) or die ("插入时出错".mysql_error());
?>

<html>
<head>
<title>简易通讯录添加记录处理</title>
</head>
<meta http-equiv="refresh" content="2;url=index.php">
<body>
已经成功添加记录,两秒后返回。
</body>
</html>











 

posted @ 2015-12-17 08:40  清风翠竹茶飘香  阅读(198)  评论(0编辑  收藏  举报