Announcement

Collapse
No announcement yet.

Mysql function and fields name

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 :

    Code:
    select * from $_POST['table'];
    Thanks for your help.

  • #2
    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';
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      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

      Comment


      • #4
        Merci aducom !!

        Quick and good reply it'is perfect.

        Comment


        • #5
          Originally posted by vrtisworks View Post
          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

          In fact it was like that :

          Code:
          $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 !

          Comment


          • #6
            Originally posted by consultin.fc View Post
            Merci aducom !!

            Quick and good reply it'is perfect.
            That's why we love him. =)
            http://www.frameworkphp.net/php/wp-c.../11/Ubarsc.jpg

            Comment


            • #7
              I almost become shy... :-P
              Albert Drent
              aducom software netherlands
              scriptcase partner, reseller, support and (turn-key) development
              www.scriptcase.eu / www.scriptcase.nl

              Comment

              Working...
              X