LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2013, 12:10 PM   #1
zak100
Member
 
Registered: Jul 2009
Posts: 225

Rep: Reputation: 2
Problem with login script


Hi,
I have written following perl code: Its giving me problem on both linux and windows. Right now i am showing the problem which i am getting on windows but its the same proble on linux. I dont have linux on my home computers.
Code:
#!/usr/bin/perl
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:
Quote:
>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.

>
Somebody plz help me in this regard.

Zulfi.
 
Old 10-28-2013, 12:58 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,004

Rep: Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333Reputation: 4333
Quote:
Originally Posted by zak100 View Post
Hi,
I have written following perl code: Its giving me problem on both linux and windows. Right now i am showing the problem which i am getting on windows but its the same proble on linux. I dont have linux on my home computers.
Code:
#!/usr/bin/perl
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:
Code:
DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual 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 line 17.
Somebody plz help me in this regard.
Spell out your words, please. And the error message is very clear: you have a syntax error in your MySQL statements. Did you look at the manuals on the module you loaded, which tell you how to format these things?? There are examples, too: researching a problem on your own is always the best first step:
http://search.cpan.org/~capttofu/DBD...b/DBD/mysql.pm

You didn't capitalize the DBI in your connect statement, and you are mixing the double and single-quotes.
Code:
$dbh = DBI->connect("DBI:mysql:TestDB", "root", "zulfi12345") or die "Unable to connect: $DBI::errstr\n";
 
Old 10-28-2013, 03:53 PM   #3
DrunkenBeetle
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Rep: Reputation: 0
Problem with login script

hi there,

You need to wrap $username and $password in quotes. You will also need to properly escape those args but quoting them first should get you going, but after that PLEASE escape them!
 
Old 10-30-2013, 05:31 AM   #4
zak100
Member
 
Registered: Jul 2009
Posts: 225

Original Poster
Rep: Reputation: 2
Hi,
I have used apostrophe and it has solved my problem:
Code:
$sth = $dbh->prepare("SELECT username, password FROM users WHERE username ='$username' and password='$password'");
$sth->execute();
But i cant understand what you mean by:

Quote:
You will also need to properly escape those args
Zulfi.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check in a script whether the shell is login or non login? frankie_DJ Programming 7 10-21-2015 10:09 AM
[SOLVED] How to edit Login Script For 3 login attempts only? IS it Possible. face123k Ubuntu 4 02-11-2013 04:12 AM
Problem with remote login (login from another machine) mamidi Linux - Newbie 5 07-20-2011 06:13 PM
[SOLVED] SSH login problem for additional users after password-less login setup uncle-c Linux - Newbie 3 02-10-2010 12:51 PM
SSH Problem - Can't login using Hostname, can login using ip address jqweezy Linux - Networking 7 01-26-2009 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration