wfbeck Posted March 4, 2009 Share Posted March 4, 2009 I am trying pass a url parameter into my sql statement to tell it what table to select based on the url paramater. IE: select * from $_Get[id] Is this possiable? I was able to do something similar to create a table based on an url parameter but can not adapt it. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/147912-need-help-with-php-telling-mysql-what-table-to-query/ Share on other sites More sharing options...
Stephen68 Posted March 4, 2009 Share Posted March 4, 2009 Ya, can't see why you can't do this... Just pass the table name in the URL www.yourplace.com?t=name Then just grab it and use it in your sql statment. <?php $table = $_GET['t']; $table = mysql_real_escape_string($table); $query = "SELECT * FROM $table; Hope that helps in some way? Quote Link to comment https://forums.phpfreaks.com/topic/147912-need-help-with-php-telling-mysql-what-table-to-query/#findComment-776308 Share on other sites More sharing options...
premiso Posted March 4, 2009 Share Posted March 4, 2009 It is possible, even with how Stephen did it. However, a major downside to that is anyone can access any table. I would setup an array with valid table names (only tables you want this script to have access to), if the get value is in the array then use it. If not throw an error to prevent anything bad happening. Just a question, why would you want to do it this way? Quote Link to comment https://forums.phpfreaks.com/topic/147912-need-help-with-php-telling-mysql-what-table-to-query/#findComment-776507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.