vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   PHP Back-End for SQL Query Form? (https://vborg.vbsupport.ru/showthread.php?t=137126)

evenmonkeys 01-21-2007 09:43 AM

PHP Back-End for SQL Query Form?
 
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 Code:

<?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.

PHP Code:

INSERT INTO tablename (field1field2field3VALUES (''''''); 

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,
PHP Code:

$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

PHP Code:

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


All times are GMT. The time now is 06:32 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00987 seconds
  • Memory Usage 1,734KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete