954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP display problems

i want the user to enter the name in the query and only after entering the name the next input text appears.
Unfortunately it doesnt work the way i want it to.

here is the code

<?php // formtest2.php


$flag = 0;

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

{
	$name = $_POST['name'];
	$flag = 1 ;

}


else $name = "(Not entered)";
//echo <<<_END

?>


	<html>
	<head>
		<title>Form Test</title>
	</head>
	<body>
	<marquee>	Your name is: $name   </marquee> 
		
		<form method="post" action="form1.php">
		What is your name?	
		<input type="text" name="name" />
		<input type="submit" />
		</form>
<?php	

	if ( $flag == 0  )
	{
		<form method="post" action="form1.php">
		What is your Uncle s NAme ?	
		<input type="text" name="name" />
		<input type="submit" />
		</form>
	}
	
	else
		echo " wish u had written your name " ;

?>


	</body>
	</html>


I dont know where i am going wrong.

rahul8590
Posting Whiz
351 posts since Mar 2009
Reputation Points: 92
Solved Threads: 20
 

Try changing line 35 to if ($flag == 1) .

You might need to change line 44 to some sort of elseif as well.

Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 

i re wrote the code in this manner . but still it doesnt seem to work

<?php // formtest2.php


$flag = 0;

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

{
	$name = $_POST['name'];
	$flag = 1 ;

}


else $name = "(Not entered)";
//echo <<<_END

?>


	<html>
	<head>
		<title>Form Test</title>
	</head>
	<body>
	<marquee>	Your name is: $name   </marquee> 
		
		<form method="post" action="form1.php">
		What is your NAme ?	
		<input type="text" name="name" />
		<input type="submit" />
		</form>

		
<?php	

	if ( $flag == 1  )
	{
?>
		<form method="post" action="form1.php">
		What is your uncles NAme ?	
		<input type="text" name="name1" />
		<input type="submit" />
		</form>
<?php	}	
		
	
	if ( $flag == 0)
		echo " wish u had written your name " ;

?>


	</body>
	</html>
rahul8590
Posting Whiz
351 posts since Mar 2009
Reputation Points: 92
Solved Threads: 20
 

I have checked latest code, it works but unfortunately "What is your NAme ?" I get even after entering the name. May be better to use following code

<?php
$flag = false;
$your_name = @$_POST['your_name'];
if (empty($your_name))
	$your_name = "(Not entered)";
	
else 
	$flag = true;
$uncle_name = @$_POST['uncle_name'];
?>
<html>
<head>
<title>Form Test</title>
</head>
<body>
<marquee> Your name is: <?php echo $your_name; ?> </marquee> 
<?php
if (!$flag)
{
?>
<form method="post" action="form1.php">
What is your NAme ?
<input type="text" name="your_name" />
<input type="submit" />
</form>
wish u had written your name
<?php
}
else
{
?>
<form method="post" action="form1.php">
What is your uncles NAme ?
<input type="text" name="uncle_name" />
<input type="hidden" name="your_name" value="<?php echo $your_name; ?>" />
<input type="submit" />
</form>
<?php
}
?>
</body>
</html>
vitana
Newbie Poster
21 posts since Mar 2010
Reputation Points: 10
Solved Threads: 6
 

Yes, above code is looking fine.

BzzBee
Posting Whiz
327 posts since Apr 2009
Reputation Points: 16
Solved Threads: 48
 

Thanks Guys.... It worked .. kudos to you.............

rahul8590
Posting Whiz
351 posts since Mar 2009
Reputation Points: 92
Solved Threads: 20
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: