//createsurvey.sql
CREATE TABLE survey (
title varchar(60) NOT NULL,
totalfield int(1),
option1 varchar(60),
option2 varchar(60),
option3 varchar(60),
option4 varchar(60),
choice1 int(6),
choice2 int(6),
choice3 int(6),
choice4 int(6),
PRIMARY KEY (title),
UNIQUE title (title)
);
title varchar(60) NOT NULL,
totalfield int(1),
option1 varchar(60),
option2 varchar(60),
option3 varchar(60),
option4 varchar(60),
choice1 int(6),
choice2 int(6),
choice3 int(6),
choice4 int(6),
PRIMARY KEY (title),
UNIQUE title (title)
);
1.survey_admin.php
<?
include "common.inc.php";
if ($Ok)
{
if ($choice=="addone")
{
if ($title=="")
{
header("Location: login_error.php?error=网上调查的标题为空\n");
}
if (($option1=="")||($option2==""))
{
header("Location: login_error.php?error=第一、二项不能为空\n");
}
$title_check = "select title from survey
where title = '$title'";
$check_result = mysql_query($title_check)
or die("不能执行网上调查。");
$check_num = mysql_num_rows($check_result);
$n=2;
if($option3!="")$n=3;
if($option4!="")$n=4;
if ($check_num == 0)
{
$sql = "insert into survey
values('$title','$n', '$option1','$option2',
'$option3','$option4',1,1,1,1)";
@mysql_query($sql) or die ("无法添加网上调查");
header("Location: on_ok.php?log_id=$log_id\n
&ok_info=网上调查添加成功");
}
else
{
header("Location: login_error.php?error=不能重复调查!\n");
}
}
else
if ($choice == "deleone")
{
$title_check = "select title from survey
where title = '$title'";
$check_result = mysql_query($title_check)
or die("不能执行网上调查。");
$check_num = mysql_num_rows($check_result);
if ($check_num == 0)
{
header("Location: login_error.php?
error=你选择的网上调查不存在。\n");
}
else
{
$title_dele = "delete from survey
where title = '$title'";
@mysql_query($title_dele) or die ("无法删除网上调查");
header("Location: on_ok.php?log_id=$log_id\n");
}
}
}
include "header.inc.php";
?>
<p align=center>
<font size=5 color=red >
网上调查的管理
</font>
</p>
<hr color=red>
<BODY>
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF; ?>">
<TABLE width=80% border=0 align=center bgcolor=yellow>
<TR bgcolor=green>
<TD height=20 align=center>
<FONT class=myYellow>
添加或者删除一个网上调查!
</FONT>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>网上调查的标题:
<INPUT type=text name=title size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第一项:
<INPUT type=text name=option1 size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第二项:
<INPUT type=text name=option2 size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第三项:
<INPUT type=text name=option3 size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第四项:
<INPUT type=text name=option4 size=60 maxlength=60>
</TD>
</TR>
<TR>
<td width="50%" align=center class=myRed>
<input type="radio" name="choice" value="addone" checked>
添  加      
         
<input type="radio" name="choice" value="deleone" >
删  除   </td>
</TR>
<TR>
<TD height=20 align=center>
<INPUT type=submit name=Ok value=" 提交 " class=myBlack>
<INPUT type=reset name=Back value=" 还原 " class=myBlack>
</TD>
</TR>
</TABLE>
</FORM>
<DIV class=myGreen align=center>
<? echo $COPYRIGHT; ?>
</DIV>
<BR>
</BODY>
</HTML>
include "common.inc.php";
if ($Ok)
{
if ($choice=="addone")
{
if ($title=="")
{
header("Location: login_error.php?error=网上调查的标题为空\n");
}
if (($option1=="")||($option2==""))
{
header("Location: login_error.php?error=第一、二项不能为空\n");
}
$title_check = "select title from survey
where title = '$title'";
$check_result = mysql_query($title_check)
or die("不能执行网上调查。");
$check_num = mysql_num_rows($check_result);
$n=2;
if($option3!="")$n=3;
if($option4!="")$n=4;
if ($check_num == 0)
{
$sql = "insert into survey
values('$title','$n', '$option1','$option2',
'$option3','$option4',1,1,1,1)";
@mysql_query($sql) or die ("无法添加网上调查");
header("Location: on_ok.php?log_id=$log_id\n
&ok_info=网上调查添加成功");
}
else
{
header("Location: login_error.php?error=不能重复调查!\n");
}
}
else
if ($choice == "deleone")
{
$title_check = "select title from survey
where title = '$title'";
$check_result = mysql_query($title_check)
or die("不能执行网上调查。");
$check_num = mysql_num_rows($check_result);
if ($check_num == 0)
{
header("Location: login_error.php?
error=你选择的网上调查不存在。\n");
}
else
{
$title_dele = "delete from survey
where title = '$title'";
@mysql_query($title_dele) or die ("无法删除网上调查");
header("Location: on_ok.php?log_id=$log_id\n");
}
}
}
include "header.inc.php";
?>
<p align=center>
<font size=5 color=red >
网上调查的管理
</font>
</p>
<hr color=red>
<BODY>
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF; ?>">
<TABLE width=80% border=0 align=center bgcolor=yellow>
<TR bgcolor=green>
<TD height=20 align=center>
<FONT class=myYellow>
添加或者删除一个网上调查!
</FONT>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>网上调查的标题:
<INPUT type=text name=title size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第一项:
<INPUT type=text name=option1 size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第二项:
<INPUT type=text name=option2 size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第三项:
<INPUT type=text name=option3 size=60 maxlength=60>
</TD>
</TR>
<TR >
<TD height=50 align=center class=myRed>调查的第四项:
<INPUT type=text name=option4 size=60 maxlength=60>
</TD>
</TR>
<TR>
<td width="50%" align=center class=myRed>
<input type="radio" name="choice" value="addone" checked>
添  加      
         
<input type="radio" name="choice" value="deleone" >
删  除   </td>
</TR>
<TR>
<TD height=20 align=center>
<INPUT type=submit name=Ok value=" 提交 " class=myBlack>
<INPUT type=reset name=Back value=" 还原 " class=myBlack>
</TD>
</TR>
</TABLE>
</FORM>
<DIV class=myGreen align=center>
<? echo $COPYRIGHT; ?>
</DIV>
<BR>
</BODY>
</HTML>
2. survey_begin.php
<html>
<!--网页的题头-->
<head>
<!-- HTML结构中的标题部分 -->
<title>
网上调查
</title>
<meta http-equiv=content-type content="text/html; charset=gb2312">
</head>
<!--正文的开始,并设置了背景图像-->
<body background="images/st.jpg" >
<!--PHP程序的开始-->
<?
/********************************
*运行一个外部的程序 *
*其作用是定义一些常用的变量 *
*并进行和goldenwind数据库的连接 *
*********************************/
include "common.inc.php";
//查询数据库中是否有调查的项目
$survey_check = "select title from survey";
$check_result = mysql_query($survey_check)
or die("不能进行网上调查。");
$check_num = mysql_num_rows($check_result);
//如果没有正在进行的调查,则报错
if ($check_num == 0)
{
header("Location: login_error.php?error=现在没有网上调查!\n");
}
else
{
//显示广告,可以是动态GIF格式
include "ad.php";
/********************************
*显示本网页的大标题 *
*它随着日期中年月的变化而变化 *
*********************************/
echo "<p align=center>";
echo " <font size=5 color=red >";
echo date(Y)."年".date(m)."月社区调查的内容是:";
echo " </font>";
echo "</p>";
echo "<hr color=red> ";
echo "<p><p><p><p><p>";
//变量$n用来记录每个调查的序号
$n=1;
$next=" [url]http://localhost/survey.php?title[/url]=";
$result = mysql_query($survey_check)
or die("不能进行网上调查。");
/********************************
*在WHILE循环中依次取出数据库表 *
*中的网上调查项,并把每一项做成 *
*一个超链接 *
*********************************/
while ($row=mysql_fetch_array($result))
{
//在网页中加入空白的符号,控制显示的位置
for ($i=1;$i<15;$i++)
echo " ";
//显示生成的超链接
echo "<A href=\"".$next.$row["title"]
."\">".$n.'.    '
. $row["title"]."</a><p><p><p>\n";
//每次循环把序号加一
$n++;
}
}
//定义一些CSS的显示类
include "header.inc.php" ;
?>
<!--显示版权信息-->
<DIV class=myGreen align=center>
<? echo $COPYRIGHT; ?>
</DIV>
</body>
</html>
<!--网页的题头-->
<head>
<!-- HTML结构中的标题部分 -->
<title>
网上调查
</title>
<meta http-equiv=content-type content="text/html; charset=gb2312">
</head>
<!--正文的开始,并设置了背景图像-->
<body background="images/st.jpg" >
<!--PHP程序的开始-->
<?
/********************************
*运行一个外部的程序 *
*其作用是定义一些常用的变量 *
*并进行和goldenwind数据库的连接 *
*********************************/
include "common.inc.php";
//查询数据库中是否有调查的项目
$survey_check = "select title from survey";
$check_result = mysql_query($survey_check)
or die("不能进行网上调查。");
$check_num = mysql_num_rows($check_result);
//如果没有正在进行的调查,则报错
if ($check_num == 0)
{
header("Location: login_error.php?error=现在没有网上调查!\n");
}
else
{
//显示广告,可以是动态GIF格式
include "ad.php";
/********************************
*显示本网页的大标题 *
*它随着日期中年月的变化而变化 *
*********************************/
echo "<p align=center>";
echo " <font size=5 color=red >";
echo date(Y)."年".date(m)."月社区调查的内容是:";
echo " </font>";
echo "</p>";
echo "<hr color=red> ";
echo "<p><p><p><p><p>";
//变量$n用来记录每个调查的序号
$n=1;
$next=" [url]http://localhost/survey.php?title[/url]=";
$result = mysql_query($survey_check)
or die("不能进行网上调查。");
/********************************
*在WHILE循环中依次取出数据库表 *
*中的网上调查项,并把每一项做成 *
*一个超链接 *
*********************************/
while ($row=mysql_fetch_array($result))
{
//在网页中加入空白的符号,控制显示的位置
for ($i=1;$i<15;$i++)
echo " ";
//显示生成的超链接
echo "<A href=\"".$next.$row["title"]
."\">".$n.'.    '
. $row["title"]."</a><p><p><p>\n";
//每次循环把序号加一
$n++;
}
}
//定义一些CSS的显示类
include "header.inc.php" ;
?>
<!--显示版权信息-->
<DIV class=myGreen align=center>
<? echo $COPYRIGHT; ?>
</DIV>
</body>
</html>
本文转自 牛海彬 51CTO博客,原文链接:http://blog.51cto.com/newhappy/76894,如需转载请自行联系原作者