好了,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 "答題失敗,一人只能參加一次答題!,<a href=# onclick="history.back();">點擊返回</a>";
}
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("<script>alert('$str');history.back();</script>");
}else{
exit("<script>alert('$str');location='$para';</script>");
}
}
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 < count($ips); $i++) {
if (!eregi ("^(10|172.16|192.168).", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
?>