97 users online (2 members and 95 guests)  

  Results 1 to 2 of 2


  1. mysql & php new line problem    Forum: PHP Forum
    Replies: 6
  2. perl and mysql-compare 2 columns    Forum: CGI Perl Forum
    Replies: 7
  3. PERL-MYSQL connection using ODBC    Forum: CGI Perl Forum
    Replies: 0
  4. how to set up Perl with MYSQL    Forum: CGI Perl Forum
    Replies: 0
  5. Replies: 3
  1. #1
    ginda's Avatar
    New User

    Join Date
    Feb 2005

    Perl dbi with mysql problem

    Im having problems using scalars in a sql statement to extract info from a mysql database, heres the code if anyone could help..

    #Windows-based Perl/DBI/example
    use DBI;

    print "Search which field? "; # print out the question
    my $data1; # declare" the variable
    $data1 = <STDIN>; # ask for the username
    chomp($data1); # remove "new line"

    print "for what data? "; # print out the question
    my $data2; # declare" the variable
    $data2 = <STDIN>; # ask for the username
    chomp($data2); # remove "new line"

    #open connection to database
    $dbh = DBI->connect('dbi:mysql:exelstock');

    #prepare and execute SQL statement
    my $string;
    $string = "SELECT * FROM stock WHERE", ( '$data1' ) = ( '$data2' ) ;
    $sth = $dbh->prepare( $string );
    die "Could not execute SQL statement ... maybe invalid?";

    #output database results
    while (@row=$sth->fetchrow_array)
    { print "@row\n" }

  2. #2
    QuietDean's Avatar

    Join Date
    Oct 2000
    Bournemouth, UK
    Hi, welcome to the forums.

    I'm well rusty on Perl, so lets go with the basics.

    Whats the result of printing $string out after you assigned the variables? That can tell us if there is anything wrong with the query.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

Tags for this Thread