我想知道是否有人可以帮助我,我目前正在做一个登录,将用户引导到页面,以便他们可以玩游戏。但是因为在发送信息时数据库上有多个帐户,它会为数据库上的所有帐户而不是一个用户显示它,任何关于如何让它将信息提交给其中一个用户的想法,如果这样做对你有意义??
这是我的登录部分,希望对您有所帮助:
<?php
include('connecttest.php');
session_start(); //we're using sessions so this is required!
if($_SESSION['loggedin'] == TRUE) {
header('location: http://html5b.mytestbox.co.uk/sessions/VolumeGame/VolumeGame1.html'); //members area
}else{
if($_POST['submitLogin']) {
//verify login from user input
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$select_user = mysql_query("SELECT COUNT(id) AS amount FROM users WHERE username = '$username' AND password = '$password' ");
$user = mysql_fetch_assoc($select_user);
$amount_found = (int)$user['amount']; //amount of users found by the query
if($amount_found > 0) {
$login_attempt = 1; //successful login attempt
$_SESSION['loggedin'] = TRUE;
$_SESSION['username'] = $username;
header('location: http://html5b.mytestbox.co.uk/sessions/VolumeGame/VolumeGame1.html'); //members area
}else{
$login_attempt = 0; //invalid login attempt
}
}
if( ($_POST['submitLogin'] AND isset($login_attempt) AND $login_attempt = 0) OR !$_POST['submitLogin'] ) {
//show login form
if($_POST['submitLogin']) { //attempted to login? (-> invalid login)
echo "<p>Invalid login. </p>";
}
?>
<form method="POST" action="login.php">
<b>Username:</b> <br /> <input type="text" name="username"> <p>
<b>Password:</b> <br /> <input type="password" name="password"> <p>
<input type="submit" name="submitLogin" value="Login!">
</form>
<?php
}
}
?>
这是将信息发送到数据库的代码:
<?php
include ("connecttest.php");
session_start();
$username = ($_POST['username']);
$_SESSION['username'] = $username;
$q1btn=$_POST['q1btnPressed'];
$q2btn=$_POST['q2btnPressed'];
$q3btn=$_POST['q3btnPressed'];
$q4btn=$_POST['q4btnPressed'];
if ($_POST['q1btnPressed'])
{
$sql=" UPDATE users
SET q1answer = '$q1btn'
WHERE username = '$username'" ;
}
if ($_POST['q2btnPressed'])
{
$sql=" UPDATE users ;
SET q2answer = '$q2btn'" ;
}
if ($_POST['q3btnPressed'])
{
$sql=" UPDATE users ;
SET q3answer = '$q3btn'" ;
}
mysql_query($sql)or die (mysql_error);
mysql_close();
?>
<?php
include "connecttest.php";
$result = mysql_query("SELECT * FROM users");
$rows=mysql_fetch_row($result);
echo json_encode($rows);
?>