rhysmeister Posted April 6, 2007 Share Posted April 6, 2007 Can anyone see what I'm doing wrong with the code? No matter what I do I can't seem to get my txtUsername and txtPassword variables posted by the page. I've returned to using php after a few years and this has me stumped at the moment. <?php require_once('Connections/localhost.php'); $FF_valUsername = $_POST['txtUsername']; // *** Start the session session_start(); // *** Validate request to log in to this site. $FF_LoginAction = $PHP_SELF; if (isset($FF_valUsername)) { $FF_valUsername=$_POST["txtUsername"]; $FF_fldUserAuthorization="mem_role"; $FF_redirectLoginSuccess="index.php"; $FF_redirectLoginFailed="index.php"; $FF_rsUser_Source="SELECT mem_email, mem_password "; if ($FF_fldUserAuthorization != "") $FF_rsUser_Source .= "," . $FF_fldUserAuthorization; $FF_rsUser_Source .= " FROM member WHERE mem_email='" . $FF_valUsername . "' AND mem_password='" . $_POST["txtPassword"] . "'"; mysql_select_db($database_localhost, $localhost); $FF_rsUser=mysql_query($FF_rsUser_Source, $localhost) or die(mysql_error()); $row_FF_rsUser = mysql_fetch_assoc($FF_rsUser); if(mysql_num_rows($FF_rsUser) > 0) { // username and password match - this is a valid user $MM_Username=$FF_valUsername; session_register("MM_Username"); if ($FF_fldUserAuthorization != "") { $MM_UserAuthorization=$row_FF_rsUser[$FF_fldUserAuthorization]; } else { $MM_UserAuthorization=""; } session_register("MM_UserAuthorization"); if (isset($accessdenied) && false) { $FF_redirectLoginSuccess = $accessdenied; } mysql_free_result($FF_rsUser); session_register("FF_login_failed"); $FF_login_failed = false; header ("Location: $FF_redirectLoginSuccess"); exit; } mysql_free_result($FF_rsUser); session_register("FF_login_failed"); $FF_login_failed = true; header ("Location: $FF_redirectLoginFailed"); exit; } ?> <?php require_once("classes/Connection.php"); $MyConnection = new Connection(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <!-- DW6 --> <head> <!-- Copyright 2005 Macromedia, Inc. All rights reserved. --> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>www.sqlcoders.co.uk</title> <link rel="stylesheet" href="3col_rightNav.css" type="text/css" /> <script type="text/javascript" src="javascript/global_javascript.js"></script> <style type="text/css"> <!-- .style1 {font-size: 150%} --> </style> </head> <body> <div id="masthead"> <h1 class="style1" id="siteName">www.sqlcoders.co.uk - The Complete SQL Resource </h1> <div id="globalNav"><a href="#" title="www.sqlcoders.co.uk">Home</a>|<a href="article.php" title="Browse our index of articles." target="iframe">Articles</a>| <a href="scripts.html" title="Browse our script archive." target="iframe">Scripts</a> | <a href="reference.html" title="Use our SQL reference to learn how to use specific functions." target="iframe">Reference</a> | <a href="faq.html" title="FAQ's for those common questions." target="iframe">FAQ's</a> | <a href="#" title="Post in our forums to help you resolve a query or problem.">Forums</a> | <a href="product.html" title="Read product and book reviews here." target="iframe">Product & Book Reviews</a>| <a href="join.html" title="Join www.sqlcoders.co.uk for full member benefits!" target="iframe">Join Us</a> | <a href="contact.html" title="Contact us here!" target="iframe">Contact</a>| <a href="online.php" title="See who's online" target="iframe">Who's Online?</a></div> <?php $result = mysql_query("SELECT mem_name, mem_created FROM member ORDER BY mem_created DESC LIMIT 1"); while($row = mysql_fetch_row($result)) { $name = $row[0]; $registered = $row[1]; } echo $FF_rsUser_Source; ?> <h2 id="pageName">SQL Articles, Scripts, FAQ's & Forums<span class="latestmember"><?php echo $name." on ".$registered; ?></span><span class="latestmember">Latest member: </span></h2><div class="latestmember"></div> <div id="breadCrumb"></div> </div> <div id="headlines"> <h2>SQL Server News</h2> <script language="javascript" src="http://www.rss-info.com/rss2.php?integration=js&windowopen=1&rss=http%3A%2F%2Fmsdn.microsoft.com%2Fsql%2Frss.xml&number=3&width=230&ifbgcol=FFFFFF&bordercol=FFFFFF&textbgcol=FFFFFF&rssbgcol=FFFFFF&showrsstitle=0&showtext=1"> </script> <h2>MySQL News</h2> <script language="javascript" src="http://www.rss-info.com/rss2.php?integration=js&windowopen=1&rss=http%3A%2F%2Fwww.mysql.com%2Fmysql.rss&number=3&width=230&ifbgcol=FFFFFF&bordercol=FFFFFF&textbgcol=FFFFFF&rssbgcol=FFFFFF&showrsstitle=0&showtext=1"> </script> <h2>Oracle News</h2> <script language="javascript" src="http://www.rss-info.com/rss2.php?integration=js&windowopen=1&rss=http%3A%2F%2Fwww.oracle.com%2Frss%2Frss_ocom_dbnews.xml&number=3&width=230&ifbgcol=FFFFFF&bordercol=FFFFFF&textbgcol=FFFFFF&rssbgcol=FFFFFF&showrsstitle=0&showtext=1"> </script> <h2>PostgreSQL News</h2> <script language="javascript" src="http://www.rss-info.com/rss2.php?integration=js&windowopen=1&rss=http%3A%2F%2Fwww.postgresql.org%2Fnews.rss&number=3&width=230&ifbgcol=FFFFFF&bordercol=FFFFFF&textbgcol=FFFFFF&rssbgcol=FFFFFF&showrsstitle=0&showtext=1"> </script> <div id="advert"> <img src="" alt="" width="107" height="66" /></div> </div> <!-- end masthead --> <div id="content"> <iframe src="iframe.html" name="iframe" width="100%" height="10000px" scrolling="Auto" frameborder="0"></iframe> </div> <!-- end content --> <div id="navBar"> <div id="search"> <?php if(!isset($txtUsername)) { echo "Not set!!!!!!"; } if ($FF_login_failed = true) { echo $FF_valUsername." = ".$txtPassword; ?> <form action="index.php" METHOD="post" enctype="" name="frmLogin" target="" id="frmLogin"> <label>Login</label> <table border="0" cellpadding="0" cellspacing="0" height="100%"> <tr> <td> <p style="font-size: 80%; float: left"> Username </td> <td> <input name="txtUsername" type="text" id="txtUsername" onfocus="changeColour(this)" onblur="revertColour(this)" size="10" style="float: right" /> </p> </td> </tr> <td> <p style="font-size: 80%; float: left"> Password </td> <td> <input name="txtPassword" type="password" id="txtPassword" onfocus="changeColour(this)" onblur="revertColour(this)" size="10" style="float: right" /> </td> </tr> <tr> <td> <? echo "<p style=\"font-size: 80; font-color=\"red\">Login Failed</p>"; } else if ($FF_login_failed = false && isset($txtUsername)) { echo "Welcome user!"; } ?> </td> <td> <input name="btnLogin" type="submit" class="btn" id="btnLogin" onmouseover="changeColour(this)" onmouseout="revertColour(this)" value="Login" style="float: right" /> </td> </tr> </table> </p> </form> </div> <div id="sectionLinks"> <h3>Latest Articles </h3> <ul> <?php $result = mysql_query("SELECT art_id, art_title FROM article WHERE art_timestamp < NOW() ORDER BY art_timestamp DESC LIMIT 5"); while($row = mysql_fetch_row($result)) { echo "<li><a href=\"article.php?article=".$row[0]."\" target=\"iframe\">".$row[1]."</a></li>"; } ?> </ul> </div> <div class="relatedLinks"> <h3>Latest Comments </h3> <ul> <?php $result = mysql_query("SELECT cmt_id, cmt_art_id,cmt_mem_id, LEFT(cmt_comment, 50), art_title, mem_name FROM comment, article, member WHERE cmt_art_id = art_id AND cmt_mem_id = mem_id ORDER BY cmt_timestamp DESC LIMIT 10"); while($row = mysql_fetch_row($result)) { echo "<li><a href=\"article.php?article=".$row[1]."#comment=".$row[0]."\" target=\"iframe\">".$row[5]." On ".$row[4]."</a></li>"; echo $row[3]; } ?> </ul> </div> <div class="relatedLinks"> <h3>Latest Scripts </h3> <ul> <?php $result = mysql_query("SELECT spt_id, spt_filename, LEFT(spt_comment, 50), mem_name FROM script, member WHERE spt_submitted_mem_id = mem_id ORDER BY spt_timestamp DESC LIMIT 5"); while($row = mysql_fetch_row($result)) { echo "<li><a href=\"script.php?script=".$row[0]."\" target=\"iframe\">".$row[1]." submitted by ".$row[3]."</a></li>"; echo $row[2]; } ?> </ul> </div> </div> <!--end navBar div --> <div id="siteInfo"> <img src="" width="44" height="22" /> <a href="#">About Us</a> | <a href="#">Site Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> | ©2007 www.sqlcoders.co.uk </div> <br /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/ Share on other sites More sharing options...
per1os Posted April 6, 2007 Share Posted April 6, 2007 Chances are enctype="" is throwing the error in the <form> declaration, remove that and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-222973 Share on other sites More sharing options...
rhysmeister Posted April 6, 2007 Author Share Posted April 6, 2007 No joy with that. Any other thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-223006 Share on other sites More sharing options...
per1os Posted April 6, 2007 Share Posted April 6, 2007 What version of PHP are you using? Prior to PHP 4 you need to use $HTTP_POST_VALUES instead of $_POST I believe. And a side note if ($FF_login_failed = true) { will always return true. Just set it to this: if ($FF_login_failed) { That will check for you. Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-223008 Share on other sites More sharing options...
rhysmeister Posted April 6, 2007 Author Share Posted April 6, 2007 I'm using php 4.4.4 on OS X. I have used $_POST on other pages with no issues at all. Obviously doing something silly! Thanks for the pointer, was using the assinment instead of a comparison operator. Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-223073 Share on other sites More sharing options...
per1os Posted April 6, 2007 Share Posted April 6, 2007 after session_start() do a : print_r($_POST); die(); and see what is displayed. Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-223079 Share on other sites More sharing options...
rhysmeister Posted April 6, 2007 Author Share Posted April 6, 2007 Ok done that, this is returned... Array ( ) Emtpy array? I presume there's got to be something up with my form? Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-223092 Share on other sites More sharing options...
per1os Posted April 6, 2007 Share Posted April 6, 2007 The only thing I see is the $PHP_SELF try setting that like this $PHP_SELF = $_SERVER['PHP_SELF']; See if that changes anything. Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-223105 Share on other sites More sharing options...
rhysmeister Posted April 6, 2007 Author Share Posted April 6, 2007 Nah, that's not it either. I'm going to have a look tomorrow with a fresh head. Thanks for you efforts. Quote Link to comment https://forums.phpfreaks.com/topic/45898-unable-to-get-posted-form-variables/#findComment-223109 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.