2014-05-09 85 views
0
$con = mysqli_connect('localhost', 'root','', 'dbname'); 
if(filter_input(INPUT_POST, "register")){ 
$username = filter_input(INPUT_POST,'username'); 
$password = filter_input(INPUT_POST,'password'); 
$email = filter_input(INPUT_POST,'email'); 

$stmtInsertUser = $con -> prepare("INSERT INTO tbl_users (username, password, email) values (?, ?, ?)"); 

$stmtInsertUser -> bind_param($username, $password, $email); 

$stmtInsertUser -> execute(); 

}如何執行安全查詢PHP

這是我的代碼,並返回該錯誤

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in C:\xampp\htdocs\xxx\xxx\PHPregister.php on line 10 

謝謝!

+0

閱讀[ bind_param的文檔](http://www.php.net/manual/en/mysqli-stmt.bind-param.php) - 你的論點是錯誤的。 – Kryten

回答

1

bind_param的第一個參數是什麼類型的輸入在

每本手冊未來的列表:http://www.php.net/manual/en/mysqli-stmt.bind-param.php(s是字符串)

$stmtInsertUser -> bind_param('sss',$username, $password, $email); 
+0

它的工作感謝,並且's'代表字符串? – Anwar

+0

是的,它確實,完整的列表:我\t對應的變量的類型爲整數,d \t對應的變量的類型爲雙,S \t對應的變量的類型爲字符串,B \t對應的變量是一個blob,將在分組 – skrilled

+0

好吧,我學會了發有用的,謝謝你:D – Anwar

1

嘗試

$stmtInsertUser->bind_param('sss',$username, $password, $email);