Jump to content
Larry Ullman's Book Forums

phpstuff

Members
  • Posts

    107
  • Joined

  • Last visited

Everything posted by phpstuff

  1. Thank you very much! You are correct it worked and was a simple mistake (if you want to call it that). I use a txt editor but it didn't color code it as if it were wrong which is interesting. I will going forward use the <> so that its easier to read the code. Thanks again!
  2. Thank you anybody/everybody in advance for your help here... Ok, I give up... Been staring at this for a while. Was given this error message: Parse error: syntax error, unexpected $end in /Applications/XAMPP/xamppfiles/htdocs/Ch. Lessons/login.php on line 58 ***Line 58 is the last line of the code. I counted parenthesis and brackets and I believe everything matches up but I obviously have something wrong and its the first time I've hit a real brick wall in this book - I was hoping to get through it without any issues!! OS = OSX10.6.4 Browser = Firefox 22.0 Here is my code: <!DOCTYPE HTML> <html> <head> <title>Login</title> </head> <body> <h1>Login</h1> <?php //Script 11.8 - login.php //This script logs a user in by checking the stored values in a txt file. //Identify the file to use: $file = '../users/users.txt'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Handle the form $loggedin = FALSE; //Not currently logged in //Enable auto detect line settings: ini_set('auto_detect_line_endings', 1); //Open the file $fp = fopen($file, 'rb'); //Loop through the file: while ( $line = fgetcsv($fp, 200, "\t") ) { //Check the file data against the submitted data: if ( ($line[0] == $_POST['username']) AND ($line[1] == md5(trim($_POST['password']))) ) { $loggedin = TRUE; //Correct username/password combination. //Stop looping through the file: break; } //End of IF. } //End of WHILE. fclose ($fp); //Close the file. //Print a message: if ($loggedin) { print '<p>You are now logged in.</p>'; } else { print'<p style="color: red;">The username or password entered do not match those on file.</p>'; } } else { //Display the form. // Leave PHP and display the form. ?> } // End of submission IF. <form action="login.php" method="post"> <p>Username: <input type="text" name="username" size="20" /></p> <p>Password: <input type="password" name="password" size="20" /></p> <input type="submit" name="submit" value="Login" /> </form> </body> </html>
  3. Jeez... nevermind... made a noobie mistake and didn't put the txt file in a seperate directory... I moved the php file to its own folder and it fixed everything...
  4. Mac OSX 10.6.4 Firefox 21.0 PROBLEM - I keep getting error message. I think the code is correct, but maybe the permissions for the txt file are not?? I included screen shots of the error, the permissions settings, and the code below. Here is my code: <!DOCTYPE HTML> <html> <head> <title>Add a Quotation</title> </head> <body> <?php //Script 11.1 - add_quote.php //This script handles and displays an HTML form, and takes text input and stores it in a text file. //First identify the file to use: $file = '../quotes.txt'; //Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { //handle the form if ( !empty($_POST['quote']) && ($_POST['quote'] != 'Enter your quotation here.') ) { //Need something to write. if (is_writable($file)) { //Confirm the file is writable file_put_contents($file, $_POST['quote'] . PHP_EOL, FILE_APPEND); //write the data //Print a message: print '<p>Your quotation has been stored.</p>'; } else { // Could not open the file. print '<p style="color: red;">Your quotation could not be stored due to a system error.</p>'; } } else { // Failed to enter a quotation. print '<p style="color: red;">Please enter a quotation!</p>'; } } // End of submitted IF. //Leave PHP and display the form: ?> <form action="add_quote.php" method="post"> <textarea name="quote" rows="5" cols="30">Enter your quotation here.</textarea><br /> <input type="submit" name="submit" value="Add this quote!" /> </form> </body> </html>
  5. LOL... I probably wont be done with the 2nd book for 2 more months, and the advanced book will probably take me until the end of the year I'm guesing!!!
  6. I did buy that book, as well as the PHP Advanced book (I'm serious about learing PHP!!). I already read the PHP & MySQL book and will be going through a second pass of the book to perform all the tutorials this time (I like to read the books first to understand the concepts and then go back through and actually do the coding. Once I get through the next book I'll probably be asking the same question as far as "what should one be able to make after reading this second book."
  7. Hi, I'm curious what one should be capable of creating after going through this book? For example, I think one should be able to: 1. Create forms such as for contact forms, registration forms, etc 2. Create simple calculators (pg 274) such as mortgage loan calculator, interest calculation, etc. 3. Storing data in a database from a form. 4. Create reusable blocks of code to speed up devel time (functions ch. 10) 5. Random # generation 6. Formatting data / numbers 7. Create a basic template website (header, footer, sidebar) 8. Using Cookies/Sessions for better user experience What else am I missing here? What else can we "make" with the knowledge in this book? Thanks!
×
×
  • Create New...