Jump to content

Index not Validating

Go to solution Solved by requinix,

Recommended Posts



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.

/* 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
<!-- 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="" />
<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"/>
<!-- 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;


/*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

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,


Link to comment
Share on other sites



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 by Nightasy
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.