|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I am using a perl shopping cart (CommerceSQL)and would like to incorporate a login script into the program. Working similar to Amzon one-click shopping. I just want the user to be able to login and have thier information pulled out of the mysql database and into the check out form. I can get the information using php but I can get it to incorporate the shopping cart info. How can I do this using perl. Here is the code I am using for php how do I convert to use in perl.
<? $connection = mysql_connect("mysql.xxxx.com","user","password") or die (mysql_error()); $db = mysql_select_db("database", $connection) or die ("Unable to select database."); if ($email == "") {$email = '%';} if ($password == "") {$password = '%';} $result = mysql_query ("SELECT * FROM register WHERE email = '$email' AND password = '$password' "); if ($row = mysql_fetch_array($result)) { do { PRINT "<b><font color='green'>First Name:<input type='text' name='name' value='$row[1]'>"; } while($row = mysql_fetch_array($result)); } else {print "Sorry, your order was not found!";} ?> Thanks |
|
#2
|
|||
|
|||
|
I'd be glad to help you out except for one problem: That's not Perl. It looks like PHP, which I'm relatively new to, and haven't done any database work with it.
If you are in fact using Perl and you just posted the wrong code, then say so and I'll help you out. The login happens in the connect. I'll go into more detail if you are using Perl.
__________________
- dsb - ![]() Perl Guy |
|
#3
|
|||
|
|||
|
Sorry if my post was confusing. Yes it is in perl, the code I posted is what I was messing around with the in php just to see if I could acutally get it to get the data I have in my registration table and I was able to. What I really want is to do the same thing in perl.
I am using a perl shopping cart, what I would like to do is when my customer is done shopping he hits a check out button then it brings up a page with in the shopping cart program so they can login by submitting thier email and a password. If the email and password match then it will pull all the information on them that is in the registration table into the check out page. They can then verify the information and check out. if you would like to view the shopping cart it is at URL just don't finalize your order this site is live. I hope I have made myself a little more clear. Thanks Scott |
|
#4
|
|||
|
|||
|
Let me make sure I'm clear.
The registration table is in a database and you want to connect to that table and check their record of registration for an email/password match. If it matches then you go ahead to the rest of the process. If that's the case then you could just do a simple SQL query like you are doing in your PHP version. If you are using their email and password to establish a connection to the database then you are going to have to create an account on the database for them, which is kind of silly, and a significant security issue. You should connect to the database using your own or a predetermined login/password to do any queries. If the problem is that you don't how to use PerlDBI then that's another story. Let me know and I'll help you with that. |
|
#5
|
|||
|
|||
|
"The registration table is in a database and you want to connect to that table and check their record of registration for an email/password match. If it matches then you go ahead to the rest of the process."
You are correct on the above. What do I need to do to make the connection in a perl script? Thanks Scott |
|
#6
|
|||
|
|||
|
Okay,
You want to use the PerlDBI module. YOu don't want to connect to the database using the email/pass provided by the user. You want to establish a connection to the database using your own user info. All this is dependent on the fact that you have the DBI module installed along with the correct DBD for type of database(ie. Oracle, mysql, etc.). Once you established a connection to the database you would prepare a statement and execute it. Then bind the results and process them as is necessary. What kind of database are you using? Do you have DBI and the correct DBD(database driver) modules installed? Do you have an account or access to an account that can be used to establish a connection to the database? These are questions that must be answered before you can proceed. Let me know if you need more help. |
|
#7
|
|||
|
|||
|
Ok I am using MySQL, it has dbi and correct DBD modules installed. Yes I have an account, I am currently using MySQL for my store.
Yes I need more help I do not know Perl very well at all and I need help to get the right code to do what we have been discussing. Thanks |
|
#8
|
|||
|
|||
|
Okay. Basically you're going to have to do a little research on DBI but this will get you started.
Code:
#!/usr/bin/perl -w # ALWAYS ALWAYS ALWAYS use this use DBI; # loads the DBI module $dbh = DBI->connect( "DBI:mysql:databasename:host", "username", "pass" ) || die $DBI::errstr, "\n"; # establishes connection or dies with error message $sth = $dbh->prepare( "SELECT * FROM tablename WHERE email = ? AND password = ?" ); # prepare the SQL query - the '?'s are placeholders, when you execute you will fill them in $sth->execute( $email, $pass ); # execute query filling in the placeholder with args passed to DBI::execute $sth->bind_columns( \$var1, \$var2, \$var3 ); # binds the results to variables, you can use as many as are needed $sth->fetch(); # fetches the results and assigns them to the variables in 'bind_columns' arg list # after that you'll be processing the information you just got I would do some research on DBI so you can get a better handle on it. Good 'ol O'Reilly has a book called Programming the Perl DBI that is really good. Also from O'reilly is Perl in a Nutshell. That book has info on many of the commonly(and not so commonly) used modules for Perl. Hope that helps. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > How do you a login script from perl to mysql. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|