Blogger Information
Blog 12
fans 0
comment 0
visits 12829
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Only variables should be passed by reference 错误处理
留情的博客
Original
857 people have browsed it


Strict Standards: Only variables should be passed by reference in D:\myphp_www\PHPTutorial\WWW\ajax\add.php on line 32

报错信息,首先来看一下原来写的

$stmt = $db ->prepare("INSERT `user`(username, email, password) VALUES(?, ?, sha1(?))");
$stmt->bind_param("sss", $username, $email, sha1($password));

看到报错的首先是将报错代码直接复制,然后百度下看看有没有相同经历的,搜索半天,解决方法没找到,倒是学到其他不少东西。没办法,然后翻译下 Only variables should be passed by reference 发现意思是 

只能通过引用传递变量

现在发现

$stmt->bind_param("sss", $username, $email, sha1($password));

sha1($password) 变成一个字符串,而通过sha1加密在预处理中已经加密了,这里进行了重复加密,而bind_param函数支持函数,支持数组,但是不支持字符串。

最后将代码改为

$stmt = $db ->prepare("INSERT `user`(username, email, password) VALUES(?, ?, sha1(?))");
$stmt->bind_param("sss", $username, $email, $password);

运行完全正常

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post