php - Cant login: mysqli_query() expects at least 2 parameters, 1 given -


i have login script doesn't work anymore. has new mysqli. changed mysql query mysqli still errors:

if (empty($errors)){     $query = "select id, username ";     $query .= "from users ";     $query .= "where username = '{$username}' ";     $query .= "and hashed_password = '{$hashed_password}' ";     $query .= "limit 1";     $result_set = mysqli_query($query);     confirm_query($result_set);     if (mysqli_num_rows($result_set) == 1){         $found_user = mysqli_fetch_array($result_set);         $_session['user_id'] = $found_user['id'];         $_session['username'] = $found_user['username'];         redirect_to("faculty.php");     } else {         $message = " username / password incorrect.";     } 

that code, mysqli_query($query); problem. when change mysqli_query($connection , $query);, don't error anymore message:

username / password incorrect.

when correct.

my connection script:

<?php require("constants.php");  $connection = mysqli_connect(db_server, db_user, db_pass, db_name); if (!$connection){     die("unable connect page");    }  ?>  <?php $db = mysqli_select_db($connection , "fm_cms"); if (!$db){     die("unable connect database");    } ?>  <?php $db = mysqli_select_db($connection , "fm_cms"); if (!$db){     die("unable connect database");    } ?> 

mysqli requires both connection , query in parameters.

mysqli_query($con,$query); 

full practical:

$con = mysqli_connect(/* connection information here*/); $result_set = mysqli_query($con,"select id table"); 

in response updated question body, mysqli_select_db used when 1 wishes change current working schema (database). in case, connecting schema specified in constant db_name. if not wanting swap schemas keep same. remove mysqli_select_db

and working mysqli query construct be:

$connection = mysqli_connect(db_server, db_user, db_pass, db_name); $query = mysqli_query($connection,"query here"); if (!$connection){     die("unable connect page");    } 

and in response to; i dont error anymore message: username / password incorrect. when correct.. please!

you being presented message because have told php so, mysqli_num_rows returning false (due incorrect mysqli_query being supplied) numbered rows not equal 1, interpreted 0 (possible refence)

mysqli query documentation


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -