PHP不会写入MySQL表
我正试图为一个网站编写一个登录函数,但出于某种奇怪的原因,MySQLiPHP不会写入MySQL表,php,mysql,mysqli,Php,Mysql,Mysqli,我正试图为一个网站编写一个登录函数,但出于某种奇怪的原因,MySQLiquery命令似乎不起作用。它通过时没有错误,但当我看表时,它是空的 下面是有问题的代码 $hash = password_hash(($_POST['password']), PASSWORD_DEFAULT); $hash = $sql_link->real_escape_string($hash); $_POST['username'] = $sql_link->real_escape_string($_PO
query
命令似乎不起作用。它通过时没有错误,但当我看表时,它是空的
下面是有问题的代码
$hash = password_hash(($_POST['password']), PASSWORD_DEFAULT);
$hash = $sql_link->real_escape_string($hash);
$_POST['username'] = $sql_link->real_escape_string($_POST['username']);
// Escape the input data
$cmd = ('INSERT INTO web_creds(email, pass, joined) ' .
'VALUES ' .
'("'.$_POST['username'].'", ' .
'"'.($hash).'", ' .
'NOW()' .
')');
if (!$sql_link->query($cmd) === TRUE) {
$err[]="input failed " . $sql_link->error;;
}
else if($sql_link->affected_rows==1)
{
$_SESSION['msg']['reg-success']="Passed";
}
else $err[]='This username is already taken!';
我运行它,并在日志中看到查询
57查询插入到web凭据(电子邮件、通行证、加入)值(“email@domain.com“,“哈希密码”,NOW())
但是当我运行select*fromWebcreds
时,我只得到EMPTY
任何帮助都将不胜感激。谢谢。(备注:您的代码易受SQL注入攻击)
它生成的SQL语句无效-您在字符串周围加了双引号(应该是单引号或使用绑定)
(注释:I,并且我预计大多数其他人认为,SLPY不在查询中使用显式数据库名称)
是否很难添加: print "<div>$cmd</div>";
您是否尝试过在phpMyAdmin中运行查询?在
web\u creds
和(电子邮件、通行证、加入)
之间有一个空格。最终查询插入到web凭据(电子邮件、传递、加入)值(“email@domain.com“,“hashed password”,NOW())
@Ashish添加空格不起作用。您在PHPmyAdmin中得到的是什么?您创建的表的存储引擎是什么?我厌倦了新的$cmd
,但仍然得到相同的结果。无论phpmyadmin如何连接都没有问题,并且可以轻松地操作数据。这开始令人沮丧。
$cmd = "INSERT INTO web_creds(email, pass, joined)
VALUES
( '$_POST[username]'
, '$hash)'
, NOW()
)";