View Full Version : PHP Back-End for SQL Query Form?
evenmonkeys
01-21-2007, 09:43 AM
I'm building a form for an admincp that I'm making and I want to be able to run queries directly from the admincp. I want it to be similar to the way vBulletin has it, but I don't need all of the confirmations that vBulletin has.
If I just used a plain old textarea box named sqlquery, what would the php look like to make it work? For some reason... I just can't get it working. >_>
Thanks.
Dismounted
01-21-2007, 10:12 AM
Take a look at https://vborg.vbsupport.ru/showthread.php?t=83122. :)
evenmonkeys
01-22-2007, 02:44 AM
I'm not trying to make a page for the vBulletin admincp. It's for something entirely different.
<?php
if($_POST[submit]){
AHHH WHAT GOES HERE!?!?!?
} else {
echo("
<textarea name='sqlquery'></textarea>
<input type='submit' name='submit'>
");
}
?>
I have no idea what to put. I don't need something unbelievably awesome. Just something simple. If I just put in the following, it doesn't work.
INSERT INTO tablename (field1, field2, field3) VALUES ('', '', '');
So I need to know how to run queries like vBulletin does it.
Adrian Schneider
01-22-2007, 03:08 AM
This is the simplest way,$db->query_write($_POST['sqlquery']);
evenmonkeys
01-22-2007, 04:37 AM
That's for vBulletin. ._. I don't want it for vBulletin. If that is for anything... then even that doesn't work.
Adrian Schneider
01-22-2007, 04:40 AM
mysql_query() instead of $db->query()
:p
evenmonkeys
01-22-2007, 04:47 AM
That will do it though? Maybe I'm doing something wrong. Let me run over it all again... but I swear that's coming back at me with an error. ._. Uno momento!
Okay- that works for one query. What if I want to do two queries in one submission?
INSERT INTO `table` (field) VALUES ('banana');
INSERT INTO `table` (field) VALUES ('banana');
Doesn't work.
Dismounted
01-22-2007, 05:05 AM
$queries = explode(";", $_POST['sqlquery']);
foreach ($queries AS $query)
{
mysql_query($query);
}
Adrian Schneider
01-22-2007, 05:10 AM
Yep, may want to add some error checking to those. Another alternative to exploding by ; is to use mysqli_multi_query() which is also useful for things like stored procedures, etc.
evenmonkeys
01-22-2007, 05:17 AM
Thanks guys. Appreciate the help!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.