Page 1 of 1
Update DB (SOLVED)
Posted: Mon Nov 23, 2015 2:42 am
by SpiritWebb
I am trying to update the database when a user logs in. It updates the last_login field and online field, however it is not doing anything. Everywhere I looked, states that its correct, but just not working. The last_login is set as DATE and the online is set to ENUM.
Code: Select all
<?php
if (isset($_POST['submit']))
{
$email=$_POST['email'];
$password=$_POST['password'];
$email=strip_tags($email);
$password=strip_tags($password);
$password=md5($password);
$query = "SELECT email,password FROM players WHERE email='$email' AND password='$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$sql = "UPDATE players SET last_login=CURDATE() SET online='1' WHERE email='$email'"; <--- This is not working
session_start();
$_SESSION['email']=$email;
header('Location: http://darkorder.rockywoodinc.com/game.php');
}
else
{
echo "<big>Wrong username or password.<A href='index.php'>Try Again</a></big>";
exit;
}
}
?>
Re: Update DB
Posted: Mon Nov 23, 2015 6:35 am
by Winawer
Code: Select all
$sql = "UPDATE players SET last_login=CURDATE(), online='1' WHERE email='$email'";
Re: Update DB
Posted: Mon Nov 23, 2015 3:33 pm
by SpiritWebb
Winawer wrote:Code: Select all
$sql = "UPDATE players SET last_login=CURDATE(), online='1' WHERE email='$email'";
It didn't update the online field or the last_login field. Checked the database and still shows 0 for online and 0000-00-00 under last_login.
Re: Update DB
Posted: Mon Nov 23, 2015 4:35 pm
by hallsofvallhalla
is online a bit? Your sending a text which may not matter. Are you getting any errors?
Re: Update DB
Posted: Mon Nov 23, 2015 4:39 pm
by SpiritWebb
hallsofvallhalla wrote:is online a bit? Your sending a text which may not matter. Are you getting any errors?
Online is a ENUM set to 0 and 1. 0 is offline, 1 is online. And there are no errors, it moves through just fine logging in, but checking the database after logging in, database has not been updated.
I know this might seem minor, but the whole thing will eventually almost revolve around an update to a row in the database.
Re: Update DB
Posted: Mon Nov 23, 2015 6:19 pm
by hallsofvallhalla
echo out the email you are imputing and check it to the one in the table. Just a thought to try.
Re: Update DB
Posted: Mon Nov 23, 2015 6:37 pm
by SpiritWebb
Its echoing the email properly. I had it echo out on the login check page before continuing to actual logged in page. I don't understand why it won't update.
Re: Update DB
Posted: Mon Nov 23, 2015 6:47 pm
by hallsofvallhalla
the only thing else I can think of is your passing a string
online='1'
do
online=1
Re: Update DB
Posted: Mon Nov 23, 2015 6:52 pm
by SpiritWebb
hallsofvallhalla wrote:the only thing else I can think of is your passing a string
online='1'
do
online=1
Tried that too before trying the first suggestion and wrapped it with ' '. But tried it again, and still nothing.
last_login is set to date in DB
online is set to enum '0','1' in DB
Code: Select all
<title>LOGIN CHECK</title>
<?php
include_once "scripts/connect.php";
?>
<?php
if (isset($_POST['submit']))
{
$email=$_POST['email'];
$password=$_POST['password'];
$email=strip_tags($email);
$password=strip_tags($password);
$password=md5($password);
$query = "SELECT email,password FROM players WHERE email='$email' AND password='$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
session_start();
$_SESSION['email']=$email;
$sql = "UPDATE players SET last_login=CURDATE(), online=1 WHERE email='$email'";
echo "<big>Logged in successfully<br>";
echo "<A href='game.php'>Continue</a></big><br>";
echo "$email";
//header('Location: http://darkorder.rockywoodinc.com/game.php');
}
else
{
echo "<big>Wrong username or password.<A href='index.php'>Try Again</a></big>";
exit;
}
}
?>
Re: Update DB
Posted: Mon Nov 23, 2015 7:05 pm
by hallsofvallhalla
oh haha I see the issue. You are just setting the variable to $SQL. Not actually running it.