Jump to content
Larry Ullman's Book Forums

olishoey

Members
  • Posts

    5
  • Joined

  • Last visited

olishoey's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I seem to have solved this issue. Now. I found a stray 'email' on one of the pages that needed to be a username. im getting something different now but hopefully can solve it myself
  2. Hi Josee Thanks for the reply, this is correct. the IF statement has actually already returned $username as being empty in the first part of the statement, my script doesn't get to the piece of code you highlighted because it has already failed the first condition
  3. Hi Guys I am having problems with my login scripts. I have adapted them slightly towards my own site so I'll post the bits that are relevant. Basically when I submit the login form it keeps coming back and telling me that the username has not been entered. Using an echo i can see that the username field is indeed blank, what I cant understand is why this is happening. the password field is fine. I'll post the relevent parts of the code, hopefully someone can help cus I'm a bit stuck here. This is the relevent part of the login_scripts file -> login_functions.inc.php from the book. function check_login($dbc, $username='', $pass='') { // setup the array that will handle the errors, errors will be passed to this array and then printed at the login screen $errors = array(); if (empty($username)) { // make sure that the username field has been filled in $errors[] = 'You forgot to enter your user name.' . "$username" . "$pass"; // if it hasnt then place this string into the errors array at the next location } else { $u = mysqli_real_escape_string($dbc, trim($username)); // make sure that characters that could disrupt the SQL statement are escaped and then whitespace is trimmed } i know that by the time it gets to the $errors[] bit that the username field is already empty this is the login form <div id='loginForm'> <form action="login.php" method="post"> <p>Username : <input type="text" name="username" size="20" maxlength="40" /></p> <p>Password : <input style="margin-left:7px;" type="password" name="pass" size="20" maxlength="20" /></p> <p><input type="submit" name="submit" value="Login" /></p> <p><input type="hidden" value="TRUE" name="submitted" /></p> </form> </div> and this is the login.php file if (isset($_POST['submitted'])) { require_once('login_scripts.php'); // the file containing the scripts that control the login process require_once('../lowisoconnect.php'); // the database connection file // check the login list ($check, $data) = check_login($dbc, $_POST['username'], $_POST['pass']); can anyone see any reason why my username field would be coming back as blank? thanks in advance for any feedback. its probably something incredibly simple.
  4. Hi Craig Thank you very much for your reply. My problems were actually a little less complicated and I'll just highlight them in case anyone else comes into this problem. I'm using the ShiftEdit IDE and when I first created the file I put it in the wrong folder. So using their interface I had cut and paste it into the correct location. They do say the cut and paste options are beta but i thought it had worked. Anyway when I just logged back in to check on the things you highlighted I found that the file had copied but the contents had not so the file my website was directing to was actually empty aside from the opening and closing php tags. After I copied my code into this file and ran it the error reporting began working and the errors craig has highlighted were commented. So basically anyone who might use ShiftEdit IDE be aware that cut and paste or copy and paste does not work as intended. Craig_UK once again thank you very much for taking the time to look at the code
  5. Hi Guys This is my first post on these forums. Up until this point I haven't had any problems but now I've hit a bit of a wall.. First off if this has been brought up before my apologise, I did search through the forum but could not find anything about this anywhere else. I have written script 8.3 out as it was described in the book and tried to run it, but all I am greeted with is a blank page. Even the header has not been loaded. I checked the code a few times and then copied the 8.3 script from the support files but this yielded the same result. My files are all in the correct folders and I just can't work out why this is happening. index.php loads fine and connect.php as it is named for me connects to the database fine. Anyone any ideas why this might be happening. I'll post my code just incase theres a problem with it but as I said I also tried copying the code exactly from the support files and that didnt work either. <?php // Registration Form $page_title = 'Register'; include ('includes/header.html'); // Check if form has been submitted: if (isset($_POST['submitted'])) { $errors = array(); // Initialise and Error Array. // Check for first name: if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } // Check for last name: if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } // Check for email if (empty($_POST['email'])) { $errors[] = 'You did not enter an email.'; } else { $e = trim($_POST['email']); } // Check for a password and match against confirmed if (empty($_POST['pass1'])) { if ($_POST['pass2'] != $_POST['pass1']) { $errors[] = 'Your passwords do not match.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'You did not enter a password.'; } // If there are no errors - Continue if (empty($errors()) { // Register the user in the database require_once ('../connect.php'); // Make the connection $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() ); $r = @mysqli_query ($dbc, $q); // Run the query. // Check to make sure the query ran ok if ($r) { // Print a thank you message echo '<h1>Thank You!</h1> <p>You are now registered. In the future you will be able to login to this site</p>'; } else { echo '<h1>System Error</h1> <p>You could not be registered because of a system error. We are doing everything we can to resolve it<br />Please try again later</p>' // Debugging Message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } mysqli_close($dbc); // Close the database connection. // Include the footer and quit script include ('includes/footer.html'); exit(); } else { echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } } ?> <h1>Regiister</h1> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="pass1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('includes/footer.html'); ?>
×
×
  • Create New...