faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 10 people (50%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

I have html inputs, with names of emp1,emp2,emp3, how do I pass these to php without hardcoding them

Jul 6th, 2002 10:41
Marcin Olak, Chris Leon,


That sould make the thing you asked about;
<?php
	if ($_POST==NULL) {
		// Print the form
		print "<FORM action='form.php3' method='post'><BR>\n";
		for ($i=1; $i<=5; $i++)
			print "emp$i <INPUT type='checkbox' 
name='emp$i'><BR>\n";
		print "<INPUT type='submit' value='submit'><BR>\n";
		print "</FORM><BR>\n";
	} else	{
		// Print the result
		for ($i=1; $i<=5; $i++) {
			$var=sprintf('emp%d',$i);
			if ($_POST[$var]=='on')
				print "$var is <FONT 
color='red'>checked</FONT><BR>\n";
					else
				print "$var is uncecked<BR>\n";
		}
		print "<A href='form.php3'>Return</A><BR>\n";
	}
?>
greetings
kyokpae