作者:小马不小 | 来源:互联网 | 2018-07-17 05:26
ec(2);好了,html 页面的css与js都写好了下面我们来看看数据库与php程序是如何实现的吧,我们先来看看数据库结构.CREATETABLEIFNOTEXISTS`su_mon_vote`( `id`int(11)NOTNULLauto_increment, `v1`varchar(100)defaultNULL
好了,html 页面的css与js都写好了下面我们来看看数据库与php程序是如何实现的吧,我们先来看看数据库结构.
CREATE TABLE IF NOT EXISTS `su_mon_vote` (
`id` int(11) NOT NULL auto_increment,
`v1` varchar(100) default NULL,
`v2` varchar(200) NOT NULL,
`v3` varchar(200) NOT NULL,
`v4` varchar(200) NOT NULL,
`v5` varchar(200) NOT NULL,
`v6` varchar(200) NOT NULL,
`name` varchar(50) NOT NULL,
`tel` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`address` varchar(200) NOT NULL,
`vip` varchar(20) NOT NULL,
`vdate` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 AUTO_INCREMENT=6 ;上面的结构是随便写的没注意数据库其它方面报.好下面我们来看看php程序是怎么判断调查的吧.
if(empty($_COOKIE["cook"])){
mysql_connect('localhost','root','mailangel') or die('database server no exists!');
mysql_select_db('vot') or die('database error!');
mysql_query("SET NAMES 'gbk'");//set document charset encode
$name =get_value("name",'post');
$tel =get_value("tel",'post');
$email =get_value("email",'post');
$add =get_value("address",'post');
$vip =get_real_ip();
$date =date("Y-m-d h:i:s");
$value =$_SERVER['HTTP_HOST'];
$array =array();
for($i=1;$i<=6;$i++){
$v ='v'.$i;
$v =get_value("$v",'post');
$array[$i-1]=$v;
if(empty($v)){
alert('对不起,你还有选项未选!','');
}
}
if( strlen($name)>100 || strlen($name)<3 ) {
alert('用户名长度3-20','');
}elseif( strlen($tel)>15 || strlen($tel)<7){
alert('请输入正确的电话号码!','');
}elseif( strlen($email)>50 || strlen($email)<10 ) {
alert('对不起,你的邮箱地址不正确!','');
}elseif( strlen($add)>100 || strlen($add)<10 ){
alert('地址长度10-100字符!','');
}
$sql ="Insert into su_mon_vote(v1,v2,v3,v4,v5,v6,name,email,address,vip,vdate,tel) value( ";
$sql =$sql."'".$array[0]."','".$array[1]."','".$array[2]."','".$array[3]."','".$array[4]."','".$array[5]."','$name',";
$sql =$sql."'$email','$add','$vip','$date','$tel')";
//mysql_query($sql) or die($sql.mysql_error());
if( mysql_query($sql)){
setCOOKIE("cook", $value, time()+7200, "/");
alert('答题成功,谢谢你的参与!','index.html');
}else{
alert('系统忙...请稍后再试','');
}
}else{
print "答题失败,一人只能参加一次答题!,点击返回";
}
function get_value($para,$para2){//获取参数的值
if( 'post'==$para2 ){
return addslashes(isset($_POST[$para])?$_POST[$para]:'');
}else{
return addslashes(isset($_GET[$para])?$_GET[$para]:'');
}
}
function alert($str,$para){//提示设置函数,
if( ''== $para){
exit("");
}else{
exit("");
}
}
function get_real_ip(){
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
for ($i = 0; $i
if (!eregi ("^(10|172.16|192.168).", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
?>