PHP Online Questionnaire Survey Program II

Source: Internet
Author: User
Tags php online strlen

OK, HTML page CSS and JS are all written down below let's look at how the database and PHP programs are implemented, we first look at the database structure.

CREATE TABLE IF not EXISTS ' Su_mon_vote ' (
' id ' int (one) not NULL auto_increment,
' v1 ' varchar default NULL,
' v2 ' varchar not NULL,
' v3 ' varchar not NULL,
' v4 ' varchar not NULL,
' V5 ' varchar not NULL,
' V6 ' varchar not NULL,
' Name ' varchar not NULL,
' Tel ' varchar not NULL,
' Email ' varchar not NULL,
' Address ' varchar is not NULL,
' VIP ' varchar not NULL,
' Vdate ' datetime not NULL,
PRIMARY KEY (' id ')
Engine=innodb DEFAULT charset=gb2312 auto_increment=6; The structure above is casually written without paying attention to the database other aspects of the report. OK, let's see how the PHP program judges the investigation.

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 the option not selected! ');
}
}

if (strlen ($name) >100 | | strlen ($name) <3) {
Alert (' username length 3-20 ', ');
}elseif (strlen ($tel) >15 | | strlen ($TEL) <7) {
Alert (' Please 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-100 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 (' The answer is successful, thank you for your participation! ', ' index.html ');

}else{
Alert (' System busy ... Please try again later ', ' ');
}

}else{
Print "The answer fails, one person can only participate in one answer!,<a href=# onclick=" History.back (); > Click return </a> ";
}


function Get_value ($para, $para 2) {//Get the value of the parameter
if (' post ' = = $para 2) {
Return Addslashes (Isset ($_post[$para])? $_post[$para]: ');
}else{
Return Addslashes (Isset ($_get[$para])? $_get[$para]: ');
}
}

function alert ($STR, $para) {//Hint setting functions,
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 ']);
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.