Jesse
Jesse

Reputation: 85

SQLError in Syntax. Trying to display table and field names

What I am trying to do is display the Table name then each of it's field names after it. it seems to work until i get to my character table, it will not display the field names and returns me this error.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character' at line 1

I looked at upgrading my MySQL but nothing happen I still managed get the error.

$showtablequery = "SHOW TABLES";
$showtablequery_result  = mysql_query($showtablequery);
while($showtablerow = mysql_fetch_array($showtablequery_result))
{
        echo "<b>$showtablerow[0]</b> - ";

        $showcolumnquery = "SHOW COLUMNS FROM $showtablerow[0]";
        $showcolumnquery_result = mysql_query($showcolumnquery) or die("Query failed with error: ".mysql_error());

        while($showcolumnfield = mysql_fetch_array($showcolumnquery_result))
        {
            echo "$showcolumnfield[0] | ";
        }
        echo "<br /><br />";
}

Upvotes: 2

Views: 158

Answers (1)

jerebear
jerebear

Reputation: 6655

Wrap your table name in ` (tick marks) so that it doesn't interpret the table name as a command.

That should fix your problem.

"SHOW COLUMNS FROM `$showtablerow[0]`";

Upvotes: 4

Related Questions