




免费预览已结束,剩余10页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第1章 PHP概述国程序8-1文件名:config.inc.php 0)$action = 用户名已存在;exit;else$action = 用户名不存在;exit;?程序8-2文件名:inc_poll_result.php/统计某一投票主题总的投票数和每一投票选项的最大投票数?if (!$poll_subject)$query = select * from $table where user_name =$user_name;$result = mysql_query($query) or die(连接数据库错误);$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); /投票选项数 /空白区的高度$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; /每一项的最大投票数 ?程序8-3文件名:show_poll.inc.php/本文件和文件frame_poll_result.php一起,实现由用户选取显示投票结果界面的功能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() 投票结果 程序8-4文件名:frame_poll_result.php/定义显示投票结果的界面frameframesetrows=,*framespacing=0border=0 frameborder=0frame src=top_poll_result.php?user_name=/在此,可以定义自己喜欢的显示投票结果的界面。程序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投票系统申请界面 申请人:/规定申请人的名字为18个字符 主页标题: 投票主题: 投票选项: 例: 好#很好#差#坏 程序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.长度超出系统设置; exit; /对输入的申请人名字的正确性进行检验if ($str_name = 申请人)for ($i=0;$i strlen($str);$i+)$one_str = substr($str,$i,1); if (ord($one_str) 122 )echo 错误: 申请人,只接受英文和数字;exit;elseif(ord($one_str)90 and ord($one_str)97) echo 错误: 申请人,只接受英文和数字;exit;/对输入的投票选项和投票主题的正确性进行检验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.应为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(主页标题,$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); /检验用户名是否存在/处理新用户申请,将数据保存到数据表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(加入数据时发生错误);$poll_result=$beg_poll_result;/*处理用户投票,如果是同一IP地址,则分析其选项;如果选择项相同,提示已投票,否则修改其投票,但投票总数不变。确定投票者IP地址的依据是:Web客户机在对服务器发送请求时需要提供一个标识,这个标识即IP地址就存储在环境变量REMOTE_ADDR里,因此通过这个环境变量就可以确定投票者的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(连接数据库错误); $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(加入数据时发生错误); 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(加入数据时发生错误); 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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工业的地域形成课件
- 子宫平滑肌瘤课件
- 子宫内膜癌课件
- 工业电器安全培训课件
- 娱乐主播教学课件
- 娱乐中科普健康知识课件
- 威海食品安全知识培训课件
- 工业机器人教学课件
- 威尼的小艇课件
- 2024年利辛县招聘城市社区专职工作人员考试真题
- 2024版2025秋贵州黔教版综合实践活动五年级上册全册教案教学设计
- 转作风重实干课件
- 村干部饮水安全培训总结课件
- 安全生产治本攻坚三年行动半年工作总结
- 单招备考科学方案
- 医美咨询培训课件
- 海船船员适任 评估规范(2024)轮机专业
- DB50-T 1463.2-2023 牛羊布鲁氏菌病防控技术规范 第2部分:人员防护
- NoSQL数据库应用与实践 课件 第1-6章 认识NoSQL - 增删改查
- 20世纪宋史研究:主要趋势、热点领域与未来展望
- 2025年度餐饮店知识产权保护与合伙人合同
评论
0/150
提交评论