Jump to content

PHP question...


eaglelegend

Recommended Posts

Why does "lastlogindate" display as "thislogin"? and nothing shows on "this login"?... on the database and also, why dont the ip adress update itself??

 

<?php

include("header.php");

 

if(isset($_POST['username']) && isset($_POST['password'])) {

                  $username = strip_tags(stripslashes($_POST['username']));

                  $password = (md5($_POST['password']));

}

 

if($username && $password) {

$check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`='$username' AND `password`='$password'"));

$ip = $_SERVER['REMOTE_ADDR'];

if($check == 1) {    

        $_SESSION['ELv2'] = $username;

        if(session_register('ELv2')){

Header("Location: index.php");

$sql = mysql_query("UPDATE members SET thislogin='$thislogindate' WHERE username='$username' LIMIT 1");

$sql = mysql_query("UPDATE members SET lastlogin='$lastlogindate' WHERE username='$username' LIMIT 1");

    $sql = mysql_query("UPDATE members SET $ip ='$_SERVER['REMOTE_ADDR']' WHERE username='$username' LIMIT 1");

 

}

else {

print "Cant set cookie";

}

}

else {

print "Sorry, username/password mismatch!";

}

 

}

else {

?>

<h2>Login</h2><p>

<form action="login.php" method="post">

Username<br>

<input type="text" name="username" class="text_box" size="20" title="Please enter the Username you registered here with." alt="Please enter the Username you registered here with."><p>

Password<br>

<input type="password" name="password" class="text_box" size="20" title="Please enter the Password you registered here with." alt="Please enter the Password you registered here with."><p>

<input type="hidden" name="ip" value="set">

<input type="submit" class="text_box" value=" Login " title="Click here to log in." alt="Click here to log in."></form>

<?php

}

include("footer.php");

?>

Link to comment
https://forums.phpfreaks.com/topic/107175-php-question/
Share on other sites

i'm not sure what your question is. but here are some tips:

 

pull your SQL out of mysql_query() so you can look at it via echo, then check for mysql_query() errors:

 

$sql = "UPDATE members SET thislogin='$thislogindate' WHERE username='$username'";
echo "sql: $sql<BR>"; // make sure the SQL looks like you expect it to.
mysql_query($sql) or die(mysql_error()); // if the query fails, stop and display the error

Link to comment
https://forums.phpfreaks.com/topic/107175-php-question/#findComment-549537
Share on other sites

$sql = mysql_query("UPDATE members SET ip ='{$_SERVER['REMOTE_ADDR']}' WHERE username='$username' LIMIT 1");

 

also just fyi all 3 of your queries are updating the same table under the same conditions so you can just use 1 query with all 3 variables.

 

edit:

 

I also assumed that you meant ip not $ip as your column name.  Or since you already set $ip to the remote address, you could do "... ip = '$ip' ..."

Link to comment
https://forums.phpfreaks.com/topic/107175-php-question/#findComment-549562
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.