Mysql function and fields name

Hello,

I am currently working on a blank application : in this app, users will be able to quickly export data from 4-5 tables (without using grids as there are several tables).

So i tried to use some Mysql functions as mysql_field_name and mysql_num_rows.

But it seems impossible to do this no ?

Would you have any idea to get the name of the columns ?
I am working with a function so the query is like :


select * from $_POST['table'];

Thanks for your help.

To get fieldnames from a table you can select on the master dictionary tables like:

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA=‘yourdatabasename’
AND TABLE_NAME=‘yourtablename’;

Please… do not ever put something directly from $_POST into an SQL statement. You WILL get hacked.

In your case, I would use $_POST[‘table’] as in index into an array of tables they can download from. If the entry isn’t found… error out the result.

Nick

Merci aducom !!

Quick and good reply it’is perfect.

[QUOTE=vrtisworks;14278]Please… do not ever put something directly from $_POST into an SQL statement. You WILL get hacked.

In your case, I would use $_POST[‘table’] as in index into an array of tables they can download from. If the entry isn’t found… error out the result.

Nick[/QUOTE]

In fact it was like that :


$export_table = $_POST['table']
$query = "select * from $export_table";

I was making some tests, but you are right i should test if the table exists !!
Thanks for the advice !

[QUOTE=consultin.fc;14286]Merci aducom !!

Quick and good reply it’is perfect.[/QUOTE]

That’s why we love him. =)

I almost become shy… :stuck_out_tongue: