Friday, 15 May 2015

php - Cant retrieve user info from database when running query, codeigniter -


I am having a problem, it should be very simple, but I can not seem to fix it. I am trying to capture the user's user ID by searching for the username in the database. But I am just getting a zero value .. Please tell me what I am doing wrong.

Here is the code for the query:

  private function get_u_id ($ user) {$ sql = "SELECT * user WHERE 'user name' =?"; $ Query = $ this- & gt; Db- & gt; Query ($ sql, array ($ user)); Forex Currency ($ query-> Result As Row) {return line $ ['id']; }}   

I am storing this information in one session, so this code is:

  $ user_session_data = array ('user' = & $ P_info ['username'], 'email' = & gt; $ this- & gt; get_user_email ($ p_info ['username']), 'u_id' => $ this- & gt; get_u_id ($ P_info ['username'], 'valid' = & gt; TRUE); // Set a session, (username, email, user_id) private function set_ession ($ user_data) {$ this- & gt; Session-> Set_user data ($ user_data); }   

And when I use this session print_r () it looks like this

  [user_data] = & gt; [User] = & gt; Wilprim [email] = & gt; [U_id] = & gt; [Valid] = & gt; You got incorrect citations in the query:  
 

$ sql = "Choose * from users where 'username' =?"; ^ - ^ -

'username' is a STRING , not field name Username is also not a reserved word, so there is no need to quote it anyway.

Any of the user:

  $ sql = "Select * from users where 'username' =? '; // note brackets $ sql =" select * In the written form, your query will return any data, if you had a user whose username was literally By format  username was .   

No comments:

Post a Comment