mysql - SQL Query in PHP not returning expected result -


I am trying to query users' level but I can not return int I am here. I do not know why, because when I get results, it means "1"

  function lvl_chcek ($ username) {$ db = new mysqli ('localhost', 'root', 'Root', 'idoctor_db'); $ lvl = $ db- & gt; Query ('Select level is the login from users' ''. $ Username. '' ''); echo $ lvl-> fetch_object () - & gt; Level; Return $ lvl-> fetch_object () - & gt; Level; }   

I also tried to do this but I have NULL

  function lvl_chcek ($ username) {$ db = new mysqli 'localhost', 'root', 'root', 'iddo_db'); $ query = $ db- & gt; Query (user login from 'select level =' '. Username' '' ''); $ Result = mysql_query ($ query); $ Array = mysql_fetch_assoc ($ result); $ Lvl = $ array ['level']; Echo $ lvl; Return $ lvl; }   

You need to get the results you need.

Try it:

  function lvl_chcek ($ user name) {$ db = new mysqli ('localhost', 'root', 'root', 'idoctor_db') ; $ Query = $ db- & gt; Query ('User login from select level =' '. $ Username' '' 1 '); $ obj = $ query- & gt; Fetch_object (); Return $ obj- & gt; Level; }   

This should be returned to the user level.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -