4 messages in com.mysql.lists.mysqlSelect with dbi perl??? Help please!
FromSent OnAttachments
Sascha Kettner06 Jan 2002 13:13 
Sascha Kettner06 Jan 2002 23:37 
Matthew Smith06 Jan 2002 23:51 
Gerald Clark07 Jan 2002 06:45 
Subject:Select with dbi perl??? Help please!
From:Sascha Kettner (sket@web.de)
Date:01/06/2002 11:37:18 PM
List:com.mysql.lists.mysql

HI!

Thanks for your Help! I´ve tried this, but when inserting the % now all my selections seem to be valid or successful, even if there is no match! What is wrong? My table for testing has the following entries:

Pin: 123456789123 msisdn:+491231234567 knd:test PIN: 123456789012 msisdn:0 knd:test

So when i insert into my form the search for test, f.e. i get both entries as a result, but even when i insert the search for 123456789123 i get both results as before but when you look at my table, you see, that only one entry should be displayed! So any other ideas?

-----Ursprüngliche Nachricht----- Von: Jesse Shy [mailto:jess@cmsmechanical.com] Gesendet: Sonntag, 6. Januar 2002 23:54 An: sket@web.de Betreff: RE: Select with dbi perl??? Help please!

I have found that unless I put a % sign either before, after or both, to denote the match part in question, that I don't get anything. Try this: LIKE '$input{pin}%'

that should do it. If not, copy the SQL statement from your script to the mysql client to test. I wouldn't retypr it, I would copy it so you try exactly what is in your script.

Good luck!

-----Original Message----- From: Sascha Kettner [mailto:sket@web.de] Sent: Sunday, January 06, 2002 4:14 PM To: mys@lists.mysql.com Subject: Select with dbi perl??? Help please!

Hi!

I have the following script to be executed via post from a web-form; the var. Pin, msisd and knd are given by the form but however, the script is not working. I always get no results as if there are no matches, but this isnt right! This is regardless which entries i submit with the form! Any ideas to fix the problem?

Thanks a lot in advance Regards

Sascha Kettner

#!/usr/bin/perl

use DBI(); ################# # Get form Data # #################

&parse_form; #################### # Script Variables # #################### $input{knd} = ""; $input{pin} = ""; $input{msisdn} = "";

######################## # What to do on submit # ########################

&dojob;

###################### # Lets have a look at the db # ######################

sub dojob {

# Now retrieve data from the table. my $dbh = DBI->connect("DBI:mysql:database=prepaid;host=localhost", "root", "sascha28", {'RaiseError' => 1}); my $sth = $dbh->prepare("SELECT * FROM pins WHERE pin LIKE '$input{pin}' OR msisdn LIKE '$input{msisdn}' OR knd LIKE '$input{knd}'"); print <<EOF; Content-type: text/html

<html> <!--# Include Virtual="/blank.html"--> <head> <title>MAKEPINS</title> <meta http-equiv="refresh" content="10;url=https:/index.html"> </head> <body> <h1 align="center">Suche Ausgeführt</h1><hr><br><br> </body> </html>

EOF $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { print "Eintrag gefunden: pin = $ref->{'pin'}, msisdn = $ref->{'msisdn'}\n, knd = $ref->{'knd'}\n\n"; } $sth->finish(); # Disconnect from the database. $dbh->disconnect(); exit; } ########################## # Get form data function # ##########################

sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $buffer = $ENV{QUERY_STRING}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$input{$name} = $value; } }

########### # The end # ###########

To request this thread, e-mail <mysq@lists.mysql.com> To unsubscribe, e-mail <mysql-unsubscribe-##L=##H@lists.mysql.com> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php