如果有测验,我有一个积分系统。当他们从测验中单击提交时,我希望他们在 mysql 中获得 +1 积分。我有一个名为登录和表用户的数据库,并且在用户中,我希望在他们完成测验时将分数更新为 1+。我使用的 quiz_form 的代码:
:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration Form</title>
</head>
<body>
<table width="328" border="0" align="center">
<form id="form1" name="form1" method="post" action="script.php">
<tr>
<td colspan="2"><h2 style="color:#FF0000">Quiz1</h2></td>
</tr>
<tr>
<td>UserName:</td>
<td>
<input name="txtusername" type="text" id="txtusername" value="<?php
session_start();
if ($_SESSION['username'])
{
echo "".$_SESSION['username'];
}
else
header ("location: welcome1.html");
?>
" />
</td>
</tr>
<tr>
<td>Who is Obama?</td>
<td><input type="password" name="txtPassword" id="txtPassword" /></td>
</tr>
<tr>
<td>What was the bing thing that were going to happend in 2012?</td>
<td><input type="text" name="txtemail" id="txtemail" /></td>
</tr>
<tr>
<td>What is a farrari?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>What is a spoon used for?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>Witch letter does this url start with?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>Are COD a game?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btnRegister" id="btnRegister" value="submit" />
</td>
</tr>
</form>
</table>
<table width="328" border="0" align="center">
<form id="form1" name="form1" method="post" action="script2.php">
<tr>
<td colspan="2"><h2 style="color:#FF0000">Quiz2</h2></td>
</tr>
<tr>
<td>UserName:</td>
<td>
<input name="txtusername" type="text" id="txtusername" value="<?php
if ($_SESSION['username'])
{
echo "".$_SESSION['username'];
}
else
header ("location: welcome1.html");
?>
" />
</td>
</tr>
<tr>
<td>Who evented facebook?</td>
<td><input type="password" name="txtPassword" id="txtPassword" /></td>
</tr>
<tr>
<td>What is a cat?</td>
<td><input type="text" name="txtemail" id="txtemail" /></td>
</tr>
<tr>
<td>What is a lamborgini?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>What is goodel used for?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>What is the last letter in this url</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>Are Counter strik a game?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btnRegister" id="btnRegister" value="submit" />
</td>
</tr>
</form>
</table>
<table width="328" border="0" align="center">
<form id="form1" name="form1" method="post" action="script3.php">
<tr>
<td colspan="2"><h2 style="color:#FF0000">Quiz3</h2></td>
</tr>
<tr>
<td>UserName:</td>
<td>
<input name="txtusername" type="text" id="txtusername" value="<?php
if ($_SESSION['username'])
{
echo "".$_SESSION['username'];
}
else
header ("location: welcome1.html");
?>
" />
</td>
</tr>
<tr>
<td>What is yourube used for?</td>
<td><input type="password" name="txtPassword" id="txtPassword" /></td>
</tr>
<tr>
<td>What is a dog?</td>
<td><input type="text" name="txtemail" id="txtemail" /></td>
</tr>
<tr>
<td>What is a kebab?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>Who is the most famed tenager in 2012/13?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>What is the 4th letter in this url?</td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td>100*2 - 5 +105 -55 +45= </td>
<td>
<input type="text" name="txtnummer" id="txtnummer" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btnRegister" id="btnRegister" value="submit" />
</td>
</tr>
</form>
</table>
</body>
</html>
这是我用于测验的脚本:
<?php
//=============Configuring Server and Database=======
$host = 'localhost';
$user = 'root';
$password = '';
//=============Data Base Information=================
$database = 'login';
$conn = mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');
//===============End Server Configuration============
//=============Starting Registration Script==========
$username = mysql_real_escape_string($_POST['txtusername']);
//=============To Encrypt Password===================
//============New Variable of Password is Now with an Encrypted Value========
if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register
{
$query = mysql_query("SELECT * FROM quiz WHERE username='$username'");
if(mysql_num_rows($query) > 0 ){
echo "Sorry but you can only take a quize once:S";
}else{
mysql_query ("insert into quiz(username)values('$username')");
$sql = "UPDATE users SET points = COALESCE(level,0)+1 WHERE username = $username";
header('location: succes.php');
}
}
?>
再次,这项工作很棒。但我只需要让他们再获得 1 分。所以如果他们有 10 分并参加了这个测验,他们在点击提交后会得到 11