Clean user input from CGI for output to WIN32::ODBC

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Clean user input from CGI for output to WIN32::ODBC

    Hi,

    I have a simple script which takes input from CGI, and outputs it to a
    database with WIN32::ODBC.

    The problem is when I encounter input with a single quote in it, it
    messes up the SQL statement for the Win32::ODBC module.

    How can I clean/phrase the input ($comments), so that it can be used
    as part of my SQL statement?


    Any help would be great... the script basically does what it is
    supposed to do, but it can be crashed by the user putting in the wrong
    input, something which I know is bad, just aren't good enough with
    Perl yet to fix :(



    Max.
    Max Harvey Guest

  2. Similar Questions and Discussions

    1. Catalog() in Win32::ODBC for MySQL
      I'm trying to pull the table information from MySQL using the Catalog() method and it gives me errors... Here's an example of my code:...
    2. Dave Roth's site (Win32::AdminMisc, Win32::ODBC, etc.) not available.
      Does anyone know of an alternate method to contact Dave Roth (other then rothd@roth.net )? It appears that his entire domain is unavailable...
    3. win32::odbc
      I am trying to fatch data from SQL database using perl win32::odbc modul. Looks like sql query does not fatch all of data. Is this possible?
    4. [ODBC] ODBC (win32) X PostgreSQL(Linux)
      Hi Fabricio, fbbsantos wrote: I need to know enough that if I sat down at your computer I could find the problem. For example, what...
    5. Win32::ODBC problem
      I'm getting lots of "Use of uninitialized value in array element at C:/Perl/lib/Win32/ODBC.pm line 256." It seems that each matching row in the...
  3. #2

    Default Re: Clean user input from CGI for output to WIN32::ODBC

    X-Ftn-To: Max Harvey

    [email]google@DELTAL.org[/email] (Max Harvey) wrote:
    >The problem is when I encounter input with a single quote in it, it
    >messes up the SQL statement for the Win32::ODBC module.
    >
    >How can I clean/phrase the input ($comments), so that it can be used
    >as part of my SQL statement?
    >
    >Any help would be great... the script basically does what it is
    >supposed to do, but it can be crashed by the user putting in the wrong
    >input, something which I know is bad, just aren't good enough with
    >Perl yet to fix :(
    perldoc DBI,
    $sth = $dbh->prepare("INSERT INTO table(foo,bar,baz) VALUES (?,?,?)");

    or you can manually backslash your values.


    --
    Matija
    Matija Papec Guest

  4. #3

    Default Re: Clean user input from CGI for output to WIN32::ODBC

    Look qt quote() in perldoc DBI

    Max Harvey wrote:
    > Hi,
    >
    > I have a simple script which takes input from CGI, and outputs it to a
    > database with WIN32::ODBC.
    >
    > The problem is when I encounter input with a single quote in it, it
    > messes up the SQL statement for the Win32::ODBC module.
    >
    > How can I clean/phrase the input ($comments), so that it can be used
    > as part of my SQL statement?
    >
    >
    > Any help would be great... the script basically does what it is
    > supposed to do, but it can be crashed by the user putting in the wrong
    > input, something which I know is bad, just aren't good enough with
    > Perl yet to fix :(
    >
    >
    >
    > Max.

    --
    Ron Reidy
    Oracle DBA

    Ron Reidy Guest

  5. #4

    Default Re: Clean user input from CGI for output to WIN32::ODBC

    On Sun, 14 Sep 2003 08:45:11 -0600
    Ron Reidy <r_reidy@comcast.net> wrote:
    > Look qt quote() in perldoc DBI
    >
    > Max Harvey wrote:
    > > Hi,
    > >
    > > I have a simple script which takes input from CGI, and outputs it
    > > to a database with WIN32::ODBC.
    ^^^^^^^^^^^^
    > >
    > > The problem is when I encounter input with a single quote in it,
    > > it messes up the SQL statement for the Win32::ODBC module.
    > >
    > > How can I clean/phrase the input ($comments), so that it can be
    > > used as part of my SQL statement?
    > >
    > >
    > > Any help would be great... the script basically does what it is
    > > supposed to do, but it can be crashed by the user putting in the
    > > wrong input, something which I know is bad, just aren't good
    > > enough with Perl yet to fix :(
    Actually, the OP needs to use WIN32::DBIODBC, then he can look up the
    'quote' method. There is no 'quote' method in WIN32::ODBC, I think.
    Or, simply switch to DBI.

    Just an observation :)

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
    for more information.

    a fortune quote ...
    Idaho state law makes it illegal for a man to give his sweetheart
    a box of candy weighing less than fifty pounds.
    James Willmore Guest

  6. #5

    Default Re: Clean user input from CGI for output to WIN32::ODBC

    James Willmore <jwillmore@cyberia.com> wrote in message news:<20030914164204.768ea317.jwillmore@cyberia.co m>...
    > On Sun, 14 Sep 2003 08:45:11 -0600
    > Ron Reidy <r_reidy@comcast.net> wrote:
    > > Look qt quote() in perldoc DBI
    > >
    > > Max Harvey wrote:
    > > > I have a simple script which takes input from CGI, and outputs it
    > > > to a database with WIN32::ODBC.
    > ^^^^^^^^^^^^
    > > >
    > > > The problem is when I encounter input with a single quote in it,
    > > > it messes up the SQL statement for the Win32::ODBC module.
    > > >
    > > > How can I clean/phrase the input ($comments), so that it can be
    > > > used as part of my SQL statement?


    Thaks for everybodys help.

    One of the early responces was to use my $sth = $dbh->prepare(sql);

    This is actually DBI ot Win32::ODBC as far as I can tell.

    Anyhow, the CGI script I was creating wasn't that large, so switching
    from Win32::ODBC to DBI and DBD::ODBC wasn't to much work.

    I have now done as advised/suggested, and I haven't managed to find
    any combination of user input which will kill my script.

    I have tried no input (underrun), lots and lots of input (overrunn),
    weird not standard charests etc., and the script seems to hold its
    own.

    Also I guess now I am usng DBI, a change of backend won't be to
    difficult if the script starts getting more work that it was expected
    to.


    Once again, thanks for all those who assisted.


    Max.
    Max Harvey Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139