writing php functions -
I am new to php and am trying to write a login function. Bit is stuck and the error is happening here My job:
connect.php
& lt ;? Php $ db_name = "coolmates"; $ Db_server = "localhost"; $ Db_user = "justron"; $ Db_pass = "Just 9004"; $ Mysqli = New MySQLi ($ db_server, $ db_user, $ db_pass, $ db_name) or die (mysqli_error ()); ? & Gt; Notice: Undefined variable: mysqli in .. \ login.php on line 14
Fatal error: Call the member function query () on a non-object <..
function login ($ username, $ password) {global $ mysqli; $ Username = trim ($ username); $ Password = trim ($ password); Do not make $ Username; First $ password; $ Login_sql = "Select * Where user from user = '" ($ username). "'And pass ='". (MD5 ($ password)). "'"; $ Login_result = $ mysqli- & gt; Query ($ login_sql) or die (mysqli_error ()); $ Line = $ login_result- & gt; Fetch_row (); If ($ line [0] == 1) {back true; } Other {return false; }} One thing that I would like to add: Do not create SQL like that, especially when using Maxcilli Use the bind parameter to do this:
$ login_result = $ mysqli-> Query ("SELECT COUNT (1) user's results from user where? = And? =?"); $ Login_result- & gt; Bind_param ("ss", $ username, md5 ($ password)); $ Login_result- & gt; Executed (); $ Login_result- & gt; Bind_result ($ count); $ Login_result- & gt; Bring (); If ($ count == 1) {// success} and {// failure}
Comments
Post a Comment