So I'm having this weird issue, where I can do SELECT statements and INSERT statements just fine, but when I do this UPDATE statement, it sorta works. It runs without errors, and even outputs that 1 row is affected. But when I check the MySQL, nothing is updated. I've echo-ed out the UPDATE statement, which has all variables being passed to it correctly. When I take that echo-ed statement and input directly into MySQL, it works fine.
I've double checked that $login_count is actually an INT Value. I've even tried converting the statement into an "INSERT ON DUPLICATE KEY UPDATE" and that has the exact same results. Am I missing something??
<?php
session_start();
require_once ('../../database_connection.php');
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$encrypted_mypassword=md5($mypassword);
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$myusername = mysql_real_escape_string($myusername);
$query_user_login = mysql_query ("SELECT * FROM members WHERE username='$myusername' and password='$encrypted_mypassword'");
// Mysql_num_row is counting table row
if(mysql_num_rows($query_user_login)==1)
// If result matched $myusername and $mypassword, table row must be 1 row
{
// Register $myusername, $mypassword and redirect to file "login_success.php"
$user_array = mysql_fetch_array($query_user_login);
$memberid = $user_array['memberid'];
$login_count = $user_array['login_count'] + 1;
$last_login = date('Y-m-d H:i:s');
$query_update_last_login = ("UPDATE `members` set `login_count` = $login_count where `memberid`=$memberid") or die(mysql_error());
mysql_close(); // Close the database connection.
$_SESSION['memberid'] = $user_array['memberid'];
$_SESSION['username'] = $user_array['username'];
header("location:../../index.php");
}
else
{
echo mysql_error();
mysql_close(); // Close the database connection.
header("location:../../index.php?action=bad_login");
}
?>