Search code examples
phpmysqldatabasemysqlivs-web-site-project

PHP, mysql SELECT statement not working


I am new to PHP and am unsure as to the syntax of mysql in php. I am trying to check a username from a data_table with the help of the following SELECT statement but seem to be encountering a syntax error. I would really appreciate any help in this matter.

$myquery = sprintf("SELECT `Username` FROM `dataTable` WHERE `Username` = \\%s", mysqli->real_escape_string($loginID));

 $userNameCheck = mysqli->query($myquery); 

 if($userNameCheck)
 {
    echo "query succeeded";
 }

Solution

  • saw that you are missing the $ sign at mysqli, don't know if that is a typo here or in your code.

    $myquery = "SELECT `Username` FROM `dataTable` WHERE `Username` = '".$mysqli->real_escape_string($loginID)."'";
    $userNameCheck = $mysqli->query($myquery);
    

    And then test what @Ray wrote