Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Banned
    Join Date
    Oct 2013
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Problem with login script

    Hi,
    I have written following perl code:
    Code:
    #!C:/Perl64/bin/perl.exe
    use DBI;
    use CGI;
    
    $cgi = new CGI;
    
    ##Create table using cgi
    $dbh = DBI->connect("dbi:mysql:TestDB", 'root','zulfi12345') or die "Unable to connect: $DBI::errstr\n";
    
    $username = $cgi->param( 'username' ) || '';
    $password = $cgi->param ('password') || '';
    $submit = $cgi->param( 'submit' ) || '';
    
    $sth = $dbh->prepare("SELECT username, password FROM users WHERE username =$username and password=$password");
    $sth->execute();
    $found=0;
    while($row = $sth->fetchrow_hashref) {
    $found=1;
    }
    if ($found==1){
    print "Welcome";}
    Its giving me following error:
    D:\Zulfi\PERL MAIN FOLDER>perl login.pl
    DBD::mysql::st execute failed: You have an error in your SQL syntax; check the m
    anual that corresponds to your MySQL server version for the right syntax to use
    near 'and password=' at line 1 at login.pl line 15.
    DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at login.pl li
    ne 17.

    D:\Zulfi\PERL MAIN FOLDER>
    Somebody plz help me in this regard.

    Zulfi.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I haven't written perl in years, but your error is a SQL error. Properties that are string based must be provided values wrapped with apostrophes.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    zak100 (10-28-2013)

  • #3
    Banned
    Join Date
    Oct 2013
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks its working.

    Zulfi.


  •  

    Posting Permissions

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