MySQL query data into a PHP variable -


I want to get a value from a MySQL database and keep it in a PHP variable.

I "User Name =" {$ this-> _username} '' '' and 'password =' ​​{$ this- & gt; _password} 'and display =' {$ this-> _display} '");

The code says invalid user name / password.

Here is the user login code:

  Mysql_connect ("localhost", "root", "test") or die (mysql_error ()); Mysql_select_db ("test") or die (mysql_error ()); $ Result = Mysql_query ("select display from ao_user". "WHERE user name = '{$ username}'") or die (msyql_error ()); $ line = mysql_fetch_assoc ($ result); echo ['display'] per line? Gt;   

and

  public function getDisplay () {mysql_connect ("localhost", "root", "test") or die ( Mysql_error (); Mysql_select_db ("test") or die (mysql_error ()); $ Result = mysql_query ("Select from ao_user". "WHERE user name = '{$ this- & gt; _username}'); $ Line = mysql_fetch_assoc ($ result); $ This- & gt; _display = $ line ['display']; $ _SESSION ['Display'] = $ this- & gt; _display; }   

No word in this program is included in the PHP variable. What am I doing wrong and how do you do it?

mysql_query handle return results, not your chosen value. You must first obtain a line, then retrieve the value from that line:

  $ result = mysql_query ("SELECT ...") or die (msyql_error ()); $ Line = mysql_fetch_assoc ($ result); Echo ['userid'] per line;    

Comments