So I have this code. Essentially what it's supposed to do is, if there are values inside the cookies, it checks them against the users table. If it checks out, it gets the userid, and then figures out if they are the admin user. (admin user has a userid value of 1) After doing this, it replaces various commented sections in the template.html file, before printing it out again. However, I have the cookie set so that the admin user is logged in, and it's STILL telling me that "SELECT * FROM users failed.." in my template file. Does anyone have any idea exactly what's going wrong? When I comment out the first conditional, and the bottom else {} bit, it keeps telling me that $userid is equal to nothing. Help would be much appreciated.
Thanks,
Spidy
(Code Below)
##there ARE values in the cookies; check them against the database
$uname_q = $dbh->quote($uname_c);
$pword_q = crypt($pword_c,682);
$pword_q = $dbh->quote($pword_q);
if($dbh->selectrow_array("SELECT * FROM users WHERE name = $uname_
+q AND pass = $pword_q")){
($userid) = $dbh->selectrow_array("SELECT userid FROM users WH
+ERE name = $uname_q AND pass=$pword_q");
if($userid == 1) {
##admin user
$template =~ s/<!--Mod (.+?)-->/$1/sg;
$template =~ s/<!--Reg (.+?)-->//sg;
$template =~ s/<!-- (.+?)-->//sg;
} else {
$template .= "\$userid = $userid";
$template =~ s/<!--Mod (.+?)-->//sg;
$template =~ s/<!--Reg (.+?)-->//sg;
$template =~ s/<!-- (.+?)-->//sg;
}
replace("loginout","Log Out");
replace("loginoutlink","logout");
$welmessage = "Welcome, $uname_c";
replace("welcome",$welmessage);
$cookieexist = 1;
} else {
$template .= "SELECT * FROM users failed..";
replace("loginout","Log In");
replace("loginoutlink","login");
$template =~ s/<!--Mod (.+?)-->//sg;
$welmessage = "You are not currently logged in.";
$template =~ s/<!--Reg (.+?)-->/$1/sg;
$template =~ s/<!-- (.+?)-->//sg;
replace("welcome",$welmessage);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.