PHP應(yīng)用實例集錦-投票系統(tǒng).doc_第1頁
PHP應(yīng)用實例集錦-投票系統(tǒng).doc_第2頁
PHP應(yīng)用實例集錦-投票系統(tǒng).doc_第3頁
PHP應(yīng)用實例集錦-投票系統(tǒng).doc_第4頁
PHP應(yīng)用實例集錦-投票系統(tǒng).doc_第5頁
免費(fèi)預(yù)覽已結(jié)束,剩余10頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

第1章 PHP概述國程序8-1文件名:config.inc.php 0)$action = 用戶名已存在;exit;else$action = 用戶名不存在;exit;?程序8-2文件名:inc_poll_result.php/統(tǒng)計某一投票主題總的投票數(shù)和每一投票選項的最大投票數(shù)?if (!$poll_subject)$query = select * from $table where user_name =$user_name;$result = mysql_query($query) or die(連接數(shù)據(jù)庫錯誤);$array_row = mysql_fetch_array($result);$poll_subject = $array_rowpoll_subject;$poll_result = $array_rowpoll_result;$poll_radio = $array_rowpoll_radio;$array_poll_radio = explode(#,$poll_radio);$array_item =explode(#,$poll_result);$item_number = sizeof($array_item); /投票選項數(shù) /空白區(qū)的高度$total_height = $top+($bar_width +$bar_distance) * $item_number + $bar_distance; $total_item = 0; $temp = 0; /定義彈出窗口的大小$td_height = 28; $open_window_height = ($total_height+40)+($item_number+8)*$td_height; $open_window_width = $total_width+50;/彈出窗口的寬for ($i = 0;$i $temp) $temp = (int)$array_item$i; /每一項的最大投票數(shù) ?程序8-3文件名:show_poll.inc.php/本文件和文件frame_poll_result.php一起,實現(xiàn)由用戶選取顯示投票結(jié)果界面的功能function openWindow(url) popupWin = window.open(url, new_page, height=, width= , top=60, left=80, toolbar= no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no)form method=POSTaction=投票 ?$title_char=48; /從0開始for ($i = 0 ;$i input type=radio value= name=radio    a href=javascript:openWindow() 投票結(jié)果 程序8-4文件名:frame_poll_result.php/定義顯示投票結(jié)果的界面frameframesetrows=,*framespacing=0border=0 frameborder=0frame src=top_poll_result.php?user_name=/在此,可以定義自己喜歡的顯示投票結(jié)果的界面。程序8-5文件名:index.php申請投票body font-family:宋體;color:3476AB;background-color:whitetd font-size= 12pta:link color =3476AB a:visted color =3476AB a:hover color = redform action= method=POST投票系統(tǒng)申請界面 申請人:/規(guī)定申請人的名字為18個字符       主頁標(biāo)題:  投票主題: 投票選項:   例: 好#很好#差#壞 程序8-6文件名:do_check.phpbody font-family:宋體;color:3476AB;background-color:whitetd font-size= 12pta:link color =3476AB a:visted color =3476AB a:hover color = red? include(config.inc.php); include(inc_poll_result.php);/輸入檢驗function check_input($str_name,$str,$length) global $array_radio,$char_everyline,$beg_poll_result;global $poll_subject,$top_char_everyline; $str = ereg_replace( ,$str); $str=htmlspecialchars(trim($str);if ($str = ) echo 錯誤: 沒有填完; exit; if (strlen($str) $length ) echo 錯誤: .$str_name.長度超出系統(tǒng)設(shè)置; exit; /對輸入的申請人名字的正確性進(jìn)行檢驗if ($str_name = 申請人)for ($i=0;$i strlen($str);$i+)$one_str = substr($str,$i,1); if (ord($one_str) 122 )echo 錯誤: 申請人,只接受英文和數(shù)字;exit;elseif(ord($one_str)90 and ord($one_str)97) echo 錯誤: 申請人,只接受英文和數(shù)字;exit;/對輸入的投票選項和投票主題的正確性進(jìn)行檢驗if ($str_name = 投票選項 or $str_name = 投票主題) $str=ereg_replace(chr(10),$str); $str=ereg_replace(chr(13),$str); if ($str_name = 投票選項) $array_radio = explode(#,$str); if (sizeof($array_radio) 8 or sizeof($array_radio) 2 ) echo 錯誤: .$str_name.應(yīng)為28個字符; exit; $beg_poll_result = 0; for ($i = 0 ;$i sizeof($array_radio) ;$i+) if ($i sizeof($array_radio)-1 ) $beg_poll_result = $beg_poll_result.#0; if ($array_radio$i = ) echo 錯誤: .$str_name.中不能有空選項; exit; $temp=$array_radio$i; if (strlen($temp)$char_everyline) $array_radio$i = chunk_split($array_radio$i, $char_everyline,rn    ); if ($str_name = 投票主題 and strlen($str) $top_char_everyline) $str = chunk_split($str, $top_char_everyline,rn); $poll_subject = $str; /開始處理輸入check_input(申請人,$user_name,8); check_input(主頁標(biāo)題,$homepage_subject,20); check_input(投票主題,$poll_subject,150); check_input(投票選項,$radio,1000); ? form method=POST action=input type=hidden name=beg_poll_result size=50value=input type=hidden name=user_name size=12 value=input type=hidden name=homepage_subject size=20 value=input type=hidden name=poll_subject size=29 value=input type=hidden name=poll_radio size=12 value= 程序8-7文件名:insert_data.phpbody font-family:宋體;color:3476AB;background-color:whitetd font-size= 12pttr height = 28a:link color =3476AB a:visted color =3476AB a:hover color = red?include(config.inc.php);isname_exist($user_name); /檢驗用戶名是否存在/處理新用戶申請,將數(shù)據(jù)保存到數(shù)據(jù)表if ($action = 用戶名不存在) $insert_data_query=INSERT INTO $table(user_name,homepage_subject,poll_subject,poll_radio,poll_result) VALUES($user_name,$homepage_subject,$poll_subject,$poll_radio,$beg_poll_result); mysql_query($insert_data_query) OR die(加入數(shù)據(jù)時發(fā)生錯誤);$poll_result=$beg_poll_result;/*處理用戶投票,如果是同一IP地址,則分析其選項;如果選擇項相同,提示已投票,否則修改其投票,但投票總數(shù)不變。確定投票者IP地址的依據(jù)是:Web客戶機(jī)在對服務(wù)器發(fā)送請求時需要提供一個標(biāo)識,這個標(biāo)識即IP地址就存儲在環(huán)境變量REMOTE_ADDR里,因此通過這個環(huán)境變量就可以確定投票者的IP地址*/if($action = 用戶名不存在)function deal_poll($user_name,$user_ip,$radio) global $table,$user_ip; if ($radio =) die(錯誤:沒有選); $query = select * from $table where user_name =$user_name; $result = mysql_query($query) or die(連接數(shù)據(jù)庫錯誤); $array_row = mysql_fetch_array($result); $ip = $array_rowip; $poll_result = $array_rowpoll_result; $poll_radio = $array_rowpoll_radio; $temp = $ip; $temp =ereg_replace($user_ip,$temp); $array_poll_radio = explode(#,$poll_radio); $str_poll_ok= 投票成功!你選擇了 .chr($radio+65).: . $array_poll_radio$radio; if ( $temp != $ip and $temp !=) /同一IP地址 $array_ip = explode($user_ip,$ip); $temp_radio = substr($array_ip1,1,1); if ($temp_radio != $radio ) /選擇項不同 $ip_str = $array_ip1; $length = strlen($ip_str)-2; $array_ip1=substr($ip_str,-$length); $str= $user_ip.#.$radio; $ip=$array_ip0.$str; $array_poll_result = explode(#,$poll_result); $temp1 = $array_poll_result(int)$radio; $temp1+=1; $temp2 = $array_poll_result(int)$temp_radio; $temp2-=1; $array_poll_result(int)$radio = $temp1; $array_poll_result(int)$temp_radio = $temp2; $poll_result = implode(#,$array_poll_result); $alter_data_query = UPDATE $table SET ip = $ip,poll_result = $poll_result WHERE user_name = $user_name; mysql_query($alter_data_query) OR die(加入數(shù)據(jù)時發(fā)生錯誤); echo $str_poll_ok; exit; else die(你已投票且選擇相同); else /不同IP地址 $ip = $ip.$user_ip.#.$radio; $array_poll_result = explode(#,$poll_result); $temp = $array_poll_result(int)$radio; $temp+=1; $array_poll_result(int)$radio = $temp; $poll_result = implode(#,$array_poll_result); $alter_data_query = UPDATE $table SET ip = $ip ,poll_result = $poll_result WHERE user_name = $user_name; mysql_query($alter_data_query) OR die(加入數(shù)據(jù)時發(fā)生錯誤); echo $str_poll_ok;exit; $query = select * from $table where user_name = $user_name ;$result = mysql_query($query);$row = mysql_fetch_array($result);$ip = $rowip;$poll_result = $rowpoll_result; deal_poll($user_name,$user_ip,$radio);?程序8-8文件名:top_poll_result.p

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論