我是PHP和MYSQL的新手,我正在努力让这个插入功能起作用。我觉得我已经正确设置了一切,但是我已经修补了一天,现在试图弄清楚这个基本查询,我没有运气。
让我先说明我知道mysql和mysqli将被弃用,我应该使用PDO但我想先了解这个基础知识,然后再深入研究另一种语言。另外,我知道存在sql-injection漏洞,我稍后会解决这个问题。
说,这是我的代码:
<?php
$con=mysql_connect("localhost","root","");
if (mysql_error())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysql_select_db( "alkouric_main" ) or die( 'Error selecting database'. mysql_error() );
$username = $_GET['username'];
$password = $_GET['password'];
$checkid = mysql_query("SELECT * from users WHERE email = '$username' AND password = '$password'");
$row = mysql_fetch_array($checkid);
$arrayemail = $row['email'];
$arraypassword = $row['password'];
echo "new array login: " . $arrayemail;
echo "<p>new array password: " . $arraypassword . "<p>";
if($arrayemail != $username) {
echo "invalid username/password";
}
else if ($arraypassword != $password) {
echo "Password is incorrect";
}
else if ($username == null or $password = null) {
echo "Username and Password cannot be blank";
}
else if ($arrayemail == $username){
echo "Login Successful! Please Wait...";
date_default_timezone_set('America/Los_Angeles');
$date = date("Y-m-d H:i:s");
$sql = 'UPDATE users
SET last_login="$date"
WHERE email="$username"';
mysql_select_db('users');
mysql_query( $sql, $con ) or die(mysql_error());
}
else {
die("could not log you in, invalid credentials.");
}
?>
所以应该发生的是,在成功登录时,日期应该插入到用户的列last_login
中,但事实并非如此。我在屏幕上成功登录时获得Login Successful! Please Wait...
回显,但没有更新记录。它可能是如此简单,我无法弄明白:(
感谢任何帮助