简体   繁体   中英

Query doesn't seem to work

I have a login form that asks for a username, a password and a file that contains a key string. I want to compare the key in this file with the key on my database and if everything matches, the user logins. The problem is that this query doesn't seem to work:

$userBusca = mysqli_query($conn, "SELECT * FROM account.login_admin WHERE login='".$login."' AND password='".$password."' AND key='".$key."'") or die(mysql_error());
if($userBusca->num_rows == 1) {

It shows me this error, but my mysqli connection is working:

Warning: mysqli_connect() expects parameter 1 to be string, object given in D:\\xampp\\htdocs\\admin\\auth\\login.php on line 3

this is my line 3:

$dbcon = mysqli_connect($conn, "5.xx.xx.xxx","user","xxxxxx");

I'm getting the content of the user file with this:

$file = $_FILES['file'];
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
//whitelist
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
$allowed = array('txt', 'cfg');
if(in_array($file_ext, $allowed)) {
if ($file_error === 0) {
    if($file_size <= 2097152) {
        $file_name_new = uniqid('', true) . '.' . $file_ext;
        $file_destination = 'uploads/' . $file_name_new;
        if(move_uploaded_file($file_tmp, $file_destination)) {
            $key_read_file = $file_destination;
            $key_load = file_get_contents($key_read_file);
            $key = $key_load;
            echo $key;

the echo returns the correct result that I want, but for some reason that error keeps popping up.

Thanks in advance

First get the function perfectly

$conn = mysqli_connect("myhost","myuser","mypassw","mybd");

So your's will be something like

$dbcon = mysqli_connect("5.xx.xx.xxx","user","xxxxxx","your_db");

I think you are mixing mysqli and mysql extensions, which will not work. You need to use.

$myConnection= mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); 

mysqli_select_db("databasename") or die ("no database");   

mysqli has many improvements over the original mysql extension

This :

 $dbcon = mysqli_connect($conn, "5.xx.xx.xxx","user","xxxxxx");

should be this :

 $dbcon = mysqli_connect("5.xx.xx.xxx","user","xxxxxx");

and this :

 mysqli_query($conn

should be this:

 mysqli_query($dbcon

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM