Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Nested if statements

$
0
0

Today doesn't seem to be my day. Having problem after problem. Haha. This time my nested IF statements don't seem to be working. If the name has been input I want to go to the next page of the form, if not I want to throw up an error message. Unfortunately this code seems to call the header() function regardless of whether the form is filled or not.

if (isset($_POST['submit'])) {
	
	if (isset($_POST['name'])) {

		$_SESSION['name'] = $_POST['name'];
		header('Location: page_2.php');
	
	}
	
	if (!isset($_POST['name'])) {

		$nameerror = "<span class=\"feedback\">Please enter valid name</span>";	
		$_SESSION['name'] = "";

	}
};

Also, to save me opening another thread later, I'm trying to call the name on the next PHP page that opens. As it's saving the data as part of a session, I thought it would be a case of just calling it again using the following code:

session_start();

$_SESSION['name'] = $name;

However, that doesn't seem to work either. Is that because I've gotten the code wrong or is that because my IF statements playing up means the name input is being stored to the session?

 

Thanks again for your help!


Viewing all articles
Browse latest Browse all 13200

Trending Articles