I was wondering if anyone can help me, I am currently working on a log in which leads the user to the page so they can play a game. But because there are multiple accounts on the database when the information is sent it displays it for all the accounts on the database not the one user, any ideas on how I can get it to submit the information to one of the users, if this made sense to you??
this is my login section, hope this helps:
<?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
}
}
?>
This is the code to send the information to the database:
<?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);
?>
Add a
WHEREclause to your query that includes the unique user id.