简明现代魔法 -> PHP服务器脚本 -> PHP数据库写入功能设计

PHP数据库写入功能设计

2009-08-20

表单代码

数据库建表语句在这里:visitors

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<link rel="stylesheet" type="text/css" href="css/formStyle.css">
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
</head>
<script language="javascript">
 function chkinput(form)
  {
    if(form.name.value=="")
	 {
	   alert("请输入您的姓名");
	   form.name.select();
	   return(false);
	 }
	if(form.companyname.value=="")
	 {
	   alert("请输入您的公司名称!");
	   form.companyname.select();
	   return(false);
	 }
     if(form.position.value=="")
	 {
	   alert("请输入您的职位!");
	   form.position.select();
	   return(false);
	 }
	 if(form.address.value=="")
	 {
	   alert("请输入您的公司地址!");
	   form.address.select();
	   return(false);
	 }
	 if(form.email.value=="")
	 {
	   alert("请输入您的邮件!");
	   form.email.select();
	   return(false);
	 }
	 if(form.tel.value=="")
	 {
	   alert("请输入您的电话!");
	   form.tel.select();
	   return(false);
	 }
	 if(form.postcode.value=="")
	 {
	   alert("请输入您的邮编!");
	   form.postcode.select();
	   return(false);
	 }
    return(true);
  }
</script>
<body>
<table width="600" border="0" align="center" style="font-family:Verdana,宋体;font-size: 12px;">
<form action="rap_Insert.php" method="post" onsubmit="return chkinput(this)">
  <tr>
    <td width="160"> </td>
    <td width="400"> </td>
  </tr>
  <tr>
    <td height="25">姓名 Name:</td>
    <td> <input type="text" name="name" size="40" maxlength="80" value="" class="inputcss" /> 
      <span class="STYLE1">*</span></td>
  </tr>
  <tr>
    <td height="25">公司名称 Company Name:</td>
    <td> <input type="text" name="companyname" size="50" maxlength="80" value="" class="inputcss" /> <span class="STYLE1">*</span></td>
  </tr>
  <tr>
    <td height="25">职位 Position:</td>
    <td> <input type="text" name="position" size="50" maxlength="80" value="" class="inputcss" /> <span class="STYLE1">*</span></td>
  </tr>
  <tr>
    <td height="25">公司地址 Address:</td>
    <td> <input type="text" name="address" size="50" maxlength="80" value="" class="inputcss" /> <span class="STYLE1">*</span></td>
  </tr>
  <tr>
    <td height="25">邮编 Postcode:</td>
    <td> <input type="text" name="postcode" size="40" maxlength="80" value="" class="inputcss" /> <span class="STYLE1">*</span></td>
  </tr>
  <tr>
    <td height="25">电话 Tel:</td>
    <td> <input type="text" name="tel" size="40" maxlength="80" value="" class="inputcss" /> <span class="STYLE1">*</span></td>
  </tr>
  <tr>
    <td height="25">传真 Fax:</td>
    <td> <input type="text" name="fax" size="50" maxlength="80" value="" class="inputcss" /></td>
  </tr>
  <tr>
    <td height="25">电子邮箱 E-mail:</td>
    <td> <input type="text" name="email" size="50" maxlength="80" value="" class="inputcss" /> <span class="STYLE1">*</span></td>
  </tr>
  <tr>
    <td height="25">网址 Website:</td>
    <td> <input type="text" name="website" size="50" maxlength="80" value="" class="inputcss" /></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="2" height="25">阁下/贵公司通过以下何种方式得知本展览会信息?</td>
  </tr>
  <tr>
    <td colspan="2" height="25"><input type = "checkbox" name="media[]" value="主办方的直邮、电子邮件" class="inputcss"/>主办方的直邮、电子邮件</td>
  </tr>
  <tr>
    <td colspan="2" height="25"><input type = "checkbox" name="media[]" value="报纸" />报纸, 请注明报纸名称:
    <input type="text" name="papername" size="20" maxlength="40" value="" class="inputcss"/></td>
  </tr>
  <tr>
    <td colspan="2" height="25"><input type = "checkbox" name="media[]" value="行业出版物广告" />行业出版物广告,请注明出版物名称:
    <input type="text" name="pressname" size="20" maxlength="40" value="" class="inputcss"/></td>
  </tr>
  <tr>
    <td colspan="2" height="25"><input type = "checkbox" name="media[]" value="网络搜索引擎" />网络搜索引擎,请注明引擎名称:
    <input type="text" name="sename" size="20" maxlength="40" value="" class="inputcss"/></td>
  </tr>
  <tr>
    <td colspan="2" height="25"><input type = "checkbox" name="media[]" value="网络宣传" />网络宣传,请注明网站名称或网址:
    <input type="text" name="sitename" size="20" maxlength="40" value="" class="inputcss"/></td>
  </tr>
  <tr>
    <td colspan="2" height="25"><input type = "checkbox" name="media[]" value="展商邀请" />展商邀请</td>
  </tr>
  <tr>
    <td colspan="2" height="25"><input type = "checkbox" name="media[]" value="其它" />其它,请说明:
    <input type="text" name="otherMedia" size="20" maxlength="40" value="" class="inputcss"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"> </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="提交信息" class="buttoncss" />  <input type="reset" value="重写" class="buttoncss"></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</form>
</table>
</body>
</html>
    

数据库插入程序代码

文件名rap_Insert.php

<?php
$db=new mysqli('localhost','root','','info');

$name = $_POST['name'];
$companyname = $_POST['companyname'];
$position = $_POST['position'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$tel = $_POST['tel'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$website = $_POST['website'];

$query="insert into visitors(name,companyname,position,address,postcode,tel,fax,email,website)";

$query.="values('$name','$companyname','$position','$address','$postcode','$tel','$fax','$email','$website')";

$db->query($query);

$db->close();
?>
随机文章推荐
网站分类


注:如需转载本文,请注明出处(原文链接),谢谢。更多精彩内容,请进入简明现代魔法首页。

进入新博客
喜欢本文,就分享它吧
给我留言
您的名字:
您的邮件:
您的网站:


 

copyright © 2009 简明现代魔法    学习、分享、进步

power by Gonn 感谢所有关心和支持本站的朋友们