Skip to content
Advertisement

How to display query results in php

I know how to make a set query display, but I need to take an input, run a statement, and display the result. Here is what I have:

HTML:

PHP:

I also want to make the statements read only so nobody can mess with my tables. im a little new to this i might need some extra explaining

Advertisement

Answer

To retrieve column names along with the result set, look at this SO question: How to get the columns names along with resultset in php/mysql?

Specifically this code snippet should help you print out the results:

Now, that said, please be very, very careful before proceeding. It looks like you’re unfamiliar with PHP, and what you’re attempting is very dangerous as it opens up a classic SQL injection vulnerability: https://xkcd.com/327/

You could restrict the possibility of damage by restricting the database permissions to read-only for the user you’re logging in as ($username and $password). Do NOT login as root – never!

If this form is only available to Admins, why not give them a true SQL IDE like Toad or SQL Server Management Studio?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement