B
B
BookerDeWitt2016-12-25 19:32:00
PHP
BookerDeWitt, 2016-12-25 19:32:00

'SELECT' how to use query result in if?

$connect=new mysqli("localhost","root","","Derk");
  function security($string)
    {
        $string=stripslashes($string);
        $string=htmlentities($string);
       // $string=mysqli_real_escape_string();
        return $string;
    }
if(isset($_POST['regist']))
{
    $RegName=$_POST['RegName'];
    $RegPassword=$_POST['RegPassword'];
    $RegName=security($RegName);
    $RegPassword=security($RegPassword);

//////////////////////////////////СМОТРЕТЬ СЮДА
    $query="SELECT * FROM 'MYLOGIN' WHERE 'Login' LIKE '$RegName'";
    $result=$connect->query($query);
    if($result->num_rows>0)// $result==true/false тоже не работают.
    {
        $error="This Username already exists, please try another name!";
        echo "ERROR";
    }
////////////////////////////////////

In theory, if the client enters a login that already exists in the database, the if block will be executed, but this does not happen, what is the error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2016-12-25
@ThunderCat

var_dump! var_dump! var_dump! var_dump! var_dump! var_dump! var_dump! var_dump! var_dump! var_dump!
Learn to look for errors in code!!!!! It’s obviously crap somewhere - it means we’re going from nose to tail, poking the wardump everywhere, first what came to the post, then we returned the security functions (whatever it is), then we check the qveri string, if it’s formed correctly, we execute the request with our hands from mayadmin For example. A piece of something is either missing or written incorrectly, the closing brace of the first if is missing altogether.

R
Rsa97, 2016-12-25
@Rsa97

RTFM

The behavior of the mysqli_num_rows() function depends on whether a buffered or unbuffered result set is used. For an unbuffered fetch, mysqli_num_rows() will not return the correct number of rows until all rows have been received and processed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question