vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   vbulletin input clean classes (https://vborg.vbsupport.ru/showthread.php?t=134110)

aragorn_reborn 12-16-2006 01:01 PM

vbulletin input clean classes
 
Hi,

I am trying to make a vbulletin powered custom page which is a html form.
The user fills the form and the data is entered into the database.

I use the database classes of vBulletin to connect to the database and insert values. My problem is that i use a insert statement as

$var1 = $_REQUEST["var1"];
INSERT INTO TABLE VALUES (1, '$var1');

Now, if $var1 already contains a single quotes, i get an database error on submitting the form. Is there some class of vBulletin that i can use to insert the data into the database so that the database stores ' as well.

Also, is there a easy way to prevent SQL injection?

Thanks

aragorn_reborn 12-19-2006 04:49 AM

I figured how to escape the single quotes error. I used the following code

Code:

$vbulletin->input->clean_array_gpc('p', array(
                'name'                => TYPE_STR,
                'category'      => TYPE_NOCLEAN,
                'contact'    => TYPE_STR,
));

$db->query_write("INSERT INTO table (id,name,category,contact) values ('','". $db->escape_string($vbulletin->GPC['name']) ."', '". $db->escape_string($vbulletin->GPC['category']) ."','". $db->escape_string($vbulletin->GPC['contact']) ."')");     

eval('print_output("' . fetch_template('testtemplate') . '");');

But i have a problem with the blank lines. For example, contact is actually a textarea where the user can enter blank lines. I need the database to store the <br> as well. When i retrieve the information from the database and print it on html, i want the text to have the same formatting as it had when the user submitted the form.

I hope my question is clear.

Please help me

aragorn_reborn 12-20-2006 02:02 PM

Pls help!!

Guest190829 12-20-2006 09:17 PM

Use the function

nl2br() after it is retrieved from the database.


All times are GMT. The time now is 12:51 PM.

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.01083 seconds
  • Memory Usage 1,711KB
  • 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
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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