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> <br />
		
		<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.

Recommended Answers

All 5 Replies

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

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

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

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> <br />
<?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>

Yes, above code is looking fine.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.