[求助]还是那个查询的话题! |
----------------------------------------
此页面用来接收从question页中传过来的值的页面test.php
--------------------------------------
<? include("db/db.link.php");
if ($HTTP_COOKIE_VARS["vote"]) {
echo "<script>alert('不可以回答了');history.back();</script>";
exit;
}
?>
<?
$xingming=$_POST["xingming"];
$sql="select xingming from userinformation ";
$result=mysql_query($sql,$conn);
//检验数据库中是否有已经回答过的人与现在从question中传过来的名字是相同的
if(($xingming=mysql_fetch_object($result)))
{
echo ("你已经回答过了,每个人只有一次回答的机会!");
//如果该姓名已经回答过了,就不给再次回答了
mysql_close($link);
}
else
{
//把题目的答案从数据库中查询出来
//本例子中我们假设答案存放在字符串$anwser中
$anwser="CABAAAACABAAAAADAAACCBDABBABCA";
//判断用户一共答对多少题
$count=0;
for($i=1;$i<31;$i++){
$anw=substr($anwser,$i-1,1);
$user_anw=$_POST["c".$i];
if($anw==$user_anw){
$count++;
}
}
//我们假设每道题目3分
$fenshu=$count*3;
echo "你的分数是:".$fenshu."<br>";
echo "共30题,答对".$count.",答错".(30-$count)."。<br>";
$xibie=$_POST["xibie"];
$banbie=$_POST["banbie"];
$xuehao=$_POST["xuehao"];
$xingming=$_POST["xingming"];
$dianhua=$_POST["dianhua"];
$email=$_POST["email"];
$strSql="insert into userinformation(xibie,banbie,xuehao,xingming,dianhua,email,score)
values('$xibie','$banbie',$xuehao,'$xingming','$dianhua','$email','$fenshu')";
$result=mysql_query($strSql,$link) or die(mysql_error());
//关闭对数据库的连接
mysql_close($link);}
?>
---------------------------------------------------
这里是db.link.php文件
<?php
//连接到MYSQL服务器
$link = mysql_connect("localhost", "keke", "keke520")
or die("Could not connect: " . mysql_error());
// 选择当前数据库
mysql_select_db('xuanzhe', $link) or die ('Can\'t use dbkangzhan: ' . mysql_error());
?>
---------------------------------------------------
其中userinformation表在xuanzhe数据库里,我的意思是说先从数据库的userinformation中进行查询xingming这个字段,如数据库中有与现在所得的姓名相同的话就提示不能再回答了,要是没有的话把相关信息写入数据库! |
|
|