Nightasy Posted May 30, 2013 Share Posted May 30, 2013 Greetings, Working with an assignment in my school I am having an issue getting an Index to validate. Been bashing my head against this all day. I am new to PHP and still learning. <?php /* Students, this script needs 4 files located in the www (Windows) or htdocs (Mac) area in the unit03 subfolder: 1. This file named index.php (this is the core script). 2. The header.html located in the includes subfolder of unit03, which minimally needs to contain HTML document structure tags up to and including the opening body tag. 3. The footer.html located in the includes subfolder of unit03, which minimally needs to contain closing body and html tags. 4. The styles.css located in the includes subfolder of unit03. This project is buggy and your task is to debug it. */ //Set the value of the page title $pagetitle = 'John Doe, IT250 Unit 3'; //Include HTML document structure tags in the header include('includes/header.php'); ?> <!-- Form elements have pre-defined styles in the related CSS. --> <form action="index.php" method="post" name="greeting"> <input type="hidden" name="hour" id="hour" value="" /> <input type="hidden" name="minute" value="" /> <fieldset> <legend>Enter Your Name</legend> <label for="fname">First</label><input type="text" name="fname" size="10"/> <label for="lname">Last</label><input type="text" name"lname" size="10" /> <input type="reset" value="Reset"/> <input type="submit" value="Submit"/> </fieldset> </form> <!-- Gets the user's time and passes it to the hidden input in the form above. Used to customize the greeting. Note the script must be after the form in order to pass the value to the form --> <script type="text/javascript"> var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); document.greeting.hour.value = h; document.greeting.minute.value = m; </script> <?php /*Check if the form was submitted. The following code block will execute upon click of the submit button, otherwise it will just show the form.*/ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // This line of code contained a syntax error $Server should be $_SERVER. //Validate data was entered if (!empty($_POST['fname']) && !empty($_POST['lname'])) { //If data is validated, initialize the text variables and convert them to proper nouns $fname = ucfirst(strtolower($_POST['fname'])); // Here I added a missing ) because it needed the ) to close the statement. $lname = ucfirst(strtolower($_POST['lname'])); // The index was incorrect here so I fixed the name. $hour = $_POST['hour']; $minute = $_POST['minute']; //Decide if it is morning, afternoon, or evening if ($hour < 12) { // This line had a closing semi colon which ended the entire else if arguments. $timeofday = "morning"; } else if ($hour < 18) { // This code was using a ( instead of an opening {. $timeofday = 'afternoon'; } else if ($hour < 24) { $timeofday = 'evening'; } echo '<p class="message">Good ' . $timeofday . " " . $fname . " " . $lname . '!</p>'; // $Fname was incorrectly spelled with a capital F. echo '<p class="message">It is ' . $hour . ':' . $minute . ' your time</p>'; echo '<a href="index.php">Start Over</a>'; } else { //Message to display if data doesn't validate echo '<p class="message">Please enter your name.</p>'; } } // This if else structure was missing a closing bracket. //Include HTML document structure tags in the footer include('includes/footer.php'); ?> I fixed quite a few errors already but I can't for the life of me figure out why the lname index is not validating. Any help or suggestions are much appreciated. Best Regards, Nightasy Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted May 30, 2013 Solution Share Posted May 30, 2013 Take a close look. Quote Link to comment Share on other sites More sharing options...
Nightasy Posted May 30, 2013 Author Share Posted May 30, 2013 (edited) OMG.... A missing equal sign. I feel really dumb now. I should have seen that cause in this assignment there was a few other little missing symbols here and there. BAH!!!! Thanks so much! Edited May 30, 2013 by Nightasy Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 30, 2013 Share Posted May 30, 2013 "This project is buggy and your task is to debug it." I'd think that'd be a big clue that there will be missing stuff :-P 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.