0

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.

4
Contributors
5
Replies
12
Views
7 Years
Discussion Span
Last Post by rahul8590
0

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

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

Edited by Fbody: n/a

0

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>
1

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.