Custom query based on php variable not working (returning no results)

QuestionsCustom query based on php variable not working (returning no results)
pcattani asked 2 years ago

I am trying to get a custom query working using a mysql statement prepared as a string before being called:

 

$sql_select_query = “select * from data WHERE owner = ‘”.$login.”‘;”;

$g->select_command = $sql_select_query;

 

This returns no results.  The error message shows that gridphp thinks the $login variable is empty.  This cannot be true.  I tested the contents of the $login variable by echoing out before hand, and it exists, but the error message shows nothing between the two single quotes: ”

 

Any guess what’s going on here?

 

Thanks.

 

 

 

6 Answers
pcattani answered 2 years ago

Sorry, some more information… I am using the auth.php page you provided for authentication.  So I am trying to use the $login variable that the user logged in with as part of the query, to return results owned by that user.

pcattani answered 2 years ago

How is this possible?   35 if (isset($login)) { 36 echo $login; 37 } else { 38 echo \”Not set: \”.$login; 39 exit(1); 40 } This simultaneously returns the login text AND falls through the else to echo \”Not set: \”

Abu Ghufran Staff answered 2 years ago

It’s because grid is loaded with 2 calls. Perhaps you need login variable in session and then use it from session.
POST variables are only available on first call, where ajax call don’t send POST again.

Ref: https://www.gridphp.com/docs/misc-faqs/#q-how-to-load-grid-based-on-_post-data-from-other-page

Beside above link, I think easy way is to save login variable in session after successful login and then use it in your query (without using POST)

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
pcattani answered 2 years ago

Thank you Abu, that\’s helpful.

 

So do you recommend starting the Session variable in the auth.php file or in my index.php file?

I need to set Session_start() in which file?   How can I ensure that the next user doesn\’t use the same Session?  Do I need to close the Session in the logout area of auth.php?

 

Thanks in advance.

pcattani answered 2 years ago

I did a Dession_start in my index file and set the Session variable in auth.php and it works, thanks.

Abu answered 2 years ago

For logout link, You will need a php page, which will call function to end the session and redirect to login page again.

Your Answer

1 + 8 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?