Update DB (SOLVED)

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Update DB (SOLVED)

Post 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;
  }
}
?>
Image

Image
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: Update DB

Post by Winawer »

Code: Select all

$sql = "UPDATE players SET last_login=CURDATE(), online='1' WHERE email='$email'"; 
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Update DB

Post 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.
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Update DB

Post by hallsofvallhalla »

is online a bit? Your sending a text which may not matter. Are you getting any errors?
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Update DB

Post 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.
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Update DB

Post by hallsofvallhalla »

echo out the email you are imputing and check it to the one in the table. Just a thought to try.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Update DB

Post 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.
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Update DB

Post by hallsofvallhalla »

the only thing else I can think of is your passing a string
online='1'

do
online=1
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Update DB

Post 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;
  }
}
?>
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Update DB

Post by hallsofvallhalla »

oh haha I see the issue. You are just setting the variable to $SQL. Not actually running it.
Post Reply

Return to “Beginner Help and Support”