php variable as table name for the grid SQL query

Questionsphp variable as table name for the grid SQL query
Tukur Dan-Asabe asked 2 years ago

I want to use php variable as table for the phpGrid as code shown below:

$getRange=$_POST[‘game’];

……
……

$g->select_command = “select * from $getRange ” ;
$g->table = ” $getRange “;

……
……

it keeps given errors as follows:

Couldn’t execute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE 1=1 LIMIT 1 OFFSET 0’ at line 1 – select * from WHERE 1=1 LIMIT 1 OFFSET 0

3 Answers
oliver answered 1 year ago

I recommend you check this page for the academic options available. This solution will surely appeal to all students.

Nihat answered 9 months ago

The right syntax is below;

$getRange=$_POST[‘game’];

$g->select_command = “select * from “. $getRange;
$g->table = $getRange;

 

it is working fine…

Jon Mills answered 9 months ago

To resolve the SQL syntax error occurring in your PHPGrid implementation, you need to ensure that the `$getRange` variable holds a valid table name before utilizing it in constructing the SQL query. This can be achieved by first verifying that `$getRange` is not empty and conforms to the pattern of a valid table name, beginning with a letter or underscore followed by letters, digits, or underscores. Upon validation, proceed to construct the `select_command` and `table` properties of your PHPGrid object using the table name stored in `$getRange`. However, if `$getRange` is found to be empty or does not meet the criteria for a valid table name, handle this scenario appropriately, such as displaying an error message or employing a default table name as a fallback. By ensuring the integrity of the `$getRange` variable as a valid table name, you can mitigate SQL syntax errors and facilitate the proper execution of your SQL query within PHPGrid. Moreover you can use this website for such assignment question which has different PHD assistance teachers.

Your Answer

9 + 1 =

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 5 / 5. Vote count: 1

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?