To store user login info into sqlite3 using perl
Hi
I need to connect to SQLite db n store user login info using perl script. The DB and the table is created. Now I need to add a part to the code so that it shows the followings 1) 0 - No error 2) -1 - record already present, if one of the primary values are already there. 3) -2 - If any of the information is invalid or incomplete, Please could anyone help me with hints or code? I am new to programming. |
Cool project, but not a trivial one for someone new to programming. (This means you've never programmed in Perl, SQL, or any language?)
It's going to be difficult to help you without any code context, so you may want to post what you've tried so far. |
To store user login info into sqlite3 using perl Reply to Thread Logged in as dhriti Title: Me
Assuming there is a db called test.db with table Cars in SQLite.
#!/usr/bin/perl use strict; use DBI; my $dbh = DBI->connect( "dbi:SQLite:dbname=test.db", { RaiseError => 1 } ) or die $DBI::errstr; my $sth = $dbh->prepare( "SELECT * FROM Cars WHERE Id=1" ); $sth->execute(); my ($id, $name, $price) = $sth->fetchrow(); print "$id $name $price\n"; ........ ......... $sth->finish(); $dbh->disconnect(); Now the condition is for each new entry to the DB table shouldn;t have same name or price. If it matches, it should show error, n shouldn't give access to entry to the table. what should be the logic? |
First, your code looks pretty good for a non programmer. It would be a lot easier to read if it were posted in [CODE] [/CODE] tags to preserve the formatting. Please edit your posts accordingly.
It seems to me that you you should be loading from the existing Db, those records that match any one of the fields of interest. If the returned dataset is non-empty, then you know that at least one record exists matching one of your fields, and you can exit with a '-1' exit code or return value. You will need to have something to search for, which can be specified by parameters passed from the commandline. Code that looks something like this may help. Code:
my $inputPrice = $ARGV[0]; --- rod. |
Thanks a lot. I got some idea. Yes its a existing DB and about the 3rd criterion what you have told is correct.
I will try now. Thank you both |
All times are GMT -5. The time now is 12:53 AM. |