ZMike1 Posted July 15, 2012 Share Posted July 15, 2012 I'm working on a project that for whatever reason I cannot get the UserName and Password from one page to post to another. It has to be something fairly easy that I'm missing __________________________________ Here is the page with the submit button __________ Here is a snip it of the other page where the submit button is <?php if($_SESSION['CustomerID'] == 0) { echo '<form method="post" action="index.php?menukey=4"> <div> <span>UserName:</span><input type="text" class="text" maxlength="32" name="UserName" /> <span>Password:</span><input type="Password" class="text" maxlength="32" name="Password" /> <input type="submit" class="button" value="Login" /><br> <span>New customer? </span><a href="index.php?menukey=2">Start here...</a> </div> </form>'; } else { echo 'Customer ID = ' . $_SESSION['CustomerID'] . '<br>'; echo 'Welcome ' . $_SESSION['FirstName'] . '<br>'; echo 'Security ID: ' . $_SESSION['SecurityID'] . '<br>'; echo '<a href="index.php?menukey=44">Logoff</a>'; } ?> ______________________________________________________________________________ Here is the log in page <?php $a = session_id(); if(empty($a)) session_start(); $CustomerID = 0; $FirstName = ""; include "MySQLConnector.txt"; // Get the data from the form: $UserName = (isset($_POST['UserName'])) ? $_POST['UserName'] : FALSE; $Password = (isset($_POST['Password'])) ? $_POST['Password'] : FALSE; //echo "Customer ID : $CustomerID <br>"; //echo "FirstName : $FirstName <br>"; //echo "UserName : $UserName <br>"; //echo "Password : $Password <br>"; $query="SELECT CustomerID, FirstName, SecurityID FROM Customers WHERE UserName= '" . $UserName . "' AND Password= '" . $Password . "' "; // Build the query $rs = @mysqli_query ($dbc, $query); // Return the Result Set WHILE ($row = mysqli_fetch_array($rs, MYSQLI_ASSOC)) { // Fetch the data $CustomerID = $row['CustomerID']; $FirstName = $row['FirstName']; $SecurityID = $row['SecurityID']; } //echo "Here's the Query: $query <br>"; mysqli_query($dbc,$query); if ($CustomerID!=0) { $_SESSION['CustomerID'] = $CustomerID; $_SESSION['FirstName'] = $FirstName; $_SESSION['SecurityID'] = $SecurityID; echo "FirstName: " . $_SESSION['FirstName']; } else { echo "Student Not Found"; } mysqli_close($dbc); //header("Location: index.php"); //Comment This Line to Debug ______________________________________________________________________________________ I have just about everything working. I'm just not sure why my password when I hit submit isnt finding it. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted July 15, 2012 Share Posted July 15, 2012 A. Why are you suppressing errors during testing? B. Why do you perform the query 2 times? Other: You should preset $CustomerID to 0, because if no rows are found $CustomerID will not equal 0 and it will set the session. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 15, 2012 Share Posted July 15, 2012 In my own opinion, you are working on a session that has not been opened yet. you forgot session_start() at the top of your opages where session is being used. Quote Link to comment 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.