Jump to content

Index not Validating


Go to solution Solved by requinix,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/278615-index-not-validating/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.