Re: Entering a Query

From: Date: Tue, 01 Apr 2003 13:20:44 +0000
Subject: Re: Entering a Query
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-26788@lists.php.net to get a copy of this message
Hi Shaun Comments inline ... On 01 Apr,2003 at 13:37 shaun shaun wrote: <snip> > Hi, > > I would be very interested to see an example of how it would be possible to > enter a query into a text area and the results of the query displayed on the > next page, similar to PHP admin I guess, are they any examples out there? > </snip> Fairly simple At its most basic you have a form :- <form method="post" action="do_query.php"> <textarea name="myquery"></textarea> <input type="submit" name="submit" value="Submit"> </form> which posts to your php page :- <?php $sql = $HTTP_POST_VARS["myquery"]; // You'll need code here to sanitize the query and make sure there's // no nasty surprises in it. // then simply create your connection (assuming a function here) $conn = db_connect(); $result = mysql_query($sql); // Code to display the result here ?> You would need to have some checking involved for the query. Also, as always, apply 'least privilege' to the user the query runs as. I don't know what you're using it for but be VERY careful - I would only allow selects here unless you're sure you know how it will be used. Hope this helps ... :-) -- Ronan e: ronan@thelittledot.com t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley

« previous php.db (#26788) next »