Jump to content

Need help with PHP telling MySQL what table to query


wfbeck

Recommended Posts

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,

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?

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.