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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.