vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   SQL query inserting extra parentheses? (https://vborg.vbsupport.ru/showthread.php?t=156376)

subnet_rx 08-27-2007 05:18 PM

SQL query inserting extra parentheses?
 
I'm trying to insert some data in the db, but the below query inserts it with parentheses. Any other combination I try, even taking off all parentheses just results in a query error. What am I doing wrong?

Code:

$db->query_read("INSERT INTO picks_groups (group_title) VALUES ('$db->escape_string($event_name)')");

Adrian Schneider 08-27-2007 05:45 PM

To call a function you need to break out of the double quotes like so,

PHP Code:

$db->query_read("
    INSERT INTO picks_groups 
        (group_title) 
    VALUES (
        '" 
$db->escape_string($event_name) . "'
    )
"
); 

Used " to close the string, and then . (concat operator) to join it with the next section which calls the escape function, and then . and " again to go back to double quoted string mode.

Another (easier to read / write for some, but not necessarily better) method is this:
PHP Code:

$escaped $db->escape_string($event_name);

$db->query_read("
    INSERT INTO picks_groups 
        (group_title) 
    VALUES (
        '
$escaped'
    )
"
); 


subnet_rx 08-27-2007 06:38 PM

Thanks, what is the proper way to clean an array inside $_POST? So, $_POST['outcome'][]

Dismounted 08-28-2007 06:42 AM

PHP Code:

$vbulletin->input->clean_gpc('p''outcome'TYPE_ARRAY_UINT); 

The last bit of the type (UINT) can be any of the others, eg. STR, NUM and FILE.

Marco van Herwaarden 08-28-2007 07:03 AM

PHP Code:

$db->query_read("INSERT INTO..... 

INSERT is a write statement, you should not use query_read() ;)

Adrian Schneider 08-28-2007 08:38 AM

lol good catch

Marco van Herwaarden 08-28-2007 01:24 PM

Hehe, i was a bit surprised you did not catch that one, and even copied it to your improved code. :D

subnet_rx 08-28-2007 04:57 PM

Thanks, I had caught that yesterday after reading through some of the vBulletin developer tools material. Thanks for that answer Dismounted.


All times are GMT. The time now is 02:17 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.01041 seconds
  • Memory Usage 1,727KB
  • 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
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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