Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.