php - My request to mysql database doesn't work properly -


this question has answer here:

i newbie in php+mysql , learn myself. got problem (i suppose may simple , stupid) can't fix it. ok. want select record database: use function connect database:

   function connect_bd() {    $result = new mysqli('localhost', 'root', '*****', 'book_kz');    if (!$result) {       return false;    } else{     $result->autocommit(true);    return $result; } } 

it works properly. wrote verification function:

function log_in($user_name, $passwrd) { //  verification of user's name , password in database // if yes - return true // otherwise - false    // connect database   $connect = connect_bd();   if (!$connect) {      return 0;   }    // verification procedure   $result = $connect->query("select * admin                          user_name='".$user_name."'                          , passwrd = sha1('".$passwrd."')");    if (!$result) {    echo "incorrect password!".$connect->mysqli_errno; // return logging in menu create_html_url("logo_in.php", "return logging menu"); return 0;      }    if ($result->num_rows>0) {       return 1;   } else {         return 0;   } $connect->close(); } 

it doesn't work. going wrong $connect->query. put query "select * admin user_name =...." directly mysql environment - works correctly. $result = $connect->query("select... shows nothing. inserted next commands echo "</br> print something</br>"; , echo "</br>print something".$result."</br>";. first command shows me string print something , next 1 shows nothing! looking failure of $result blocks printing. i've checked samples mysqli::query , didn't found wrong. appreciated ready me. thank in advance....

when call class constructor new return class. piece of code wrong:

$result = new mysqli('localhost', 'root', '*****', 'book_kz'); if (!$result) echo "oh, there's error!"; 

instead do:

$mysqli = new mysqli('localhost', 'root', '*****', 'book_kz');  // connect_errno exists connection attempt failed! if ($mysqli->connect_errno) {   echo "error: failed make mysql connection, here why: \n";   echo "errno: " . $mysqli->connect_errno . "\n";   echo "error: " . $mysqli->connect_error . "\n";   exit; } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -