Ec (2); well, css and js on the html & nbsp; page have been written. Let's take a look at how the database and php programs are implemented. Let's first look at the database structure. CREATETABLEIFNOTEXISTS 'su _ mon_vote '(& nbsp; 'id' int (11) NOTNULLauto_increment, & nbsp; 'v1 'varchar (100) defaultNULL script ec (2 ); script
Okay, css and js on the html page are all written. Let's take a look at how the database and php programs are implemented. Let's first look at the database structure.
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; The above structure is casually written without paying attention to other aspects of the database. Let's take a look at how the php program judges and investigates.
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 ('Sorry, you still have option not selected! ','');
}
}
If (strlen ($ name)> 100 | strlen ($ name) <3 ){
Alert ('username length: 3-20 ','');
} Elseif (strlen ($ tel)> 15 | strlen ($ tel) <7 ){
Alert ('Enter the correct phone number! ','');
} Elseif (strlen ($ email)> 50 | strlen ($ email) <10 ){
Alert ('Sorry, your email address is incorrect! ','');
} Elseif (strlen ($ add)> 100 | strlen ($ add) <10 ){
Alert ('address length: 10-characters! ','');
}
$ 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 ('answer successful. Thank you for your participation! ', 'Index.html ');
} Else {
Alert ('System busy... please try again later ','');
}
} Else {
Print "An error occurred while answering questions. Only one person can answer questions once !, Click to return ";
}
Function get_value ($ para, $ para2) {// obtain the parameter value
If ('post' = $ para2 ){
Return addslashes (isset ($ _ POST [$ para])? $ _ POST [$ para]: '');
} Else {
Return addslashes (isset ($ _ GET [$ para])? $ _ GET [$ para]: '');
}
}
Function alert ($ str, $ para) {// The system prompts you to set the function,
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 ']);
}
?>