Page 1 of 1

Another forms question

Posted: Wed Oct 04, 2006 2:44 pm
by PaulD233
My php signup page. Here's what I need help with. I need to have the Appetizers and Desserts section have 8 slots to sign up. I want the Drinks section to only have 4 slots to sign up. Any instruction would be appreciated. Below is my code. Thank you.

Please use PHP and CODE tags.

Code: Select all

<?php
$dbh=mysql_connect ("localhost", "dvdcreat_dev", "dev") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dvdcreat_unionsbcdevelopment"); 
#echo "you did it!!";
$types = array ("Appetizer","Desserts","Drinks");
$count = 8;
if ($_POST)
{
    #print_r ($_POST);
	$signeduptypes=array();
	foreach($_POST as $name => $value)
	{
		if ($value)
		{	
			$newname=explode("_",$name);
			$newname=$newname [0];
			$signeduptypes[]=$newname;
			#echo "You signed up for $newname";
			$sql="insert into signup(type,name) values('$newname','$value')";
			mysql_query($sql);
		}
	}
	if ($signeduptypes)$message="You signed up for ".implode(", ",$signeduptypes);
	header("Location: ".$_SERVER["SCRIPT_NAME"]."?message=".urlencode($message));
}
$sql="select type, name from signup";
$result=mysql_query($sql);
#print_r($result);
while($savedresults=mysql_fetch_array($result))
{
	$signupsheet[$savedresults[0]][]=$savedresults[1];
}
$message=$_GET["message"];
#print_r($savedresults);
#print_r ($signupsheet);
?>

Code: Select all

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>the Union - Sign Up Sheet</title>
</head>

<body bgcolor="#FFFFCD">

<form method="POST" action="<?=$PHP_SELF?>" name="Signup">
	
	<h2><font face="Comic Sans MS"><?=$message?></font></h2>
	<p><font face="Comic Sans MS" color="#FF9900">Please sign up for at least one of the following:</font></p>
	<table border="0" style="border-collapse: collapse" cellpadding="10" width="509" id="table1">
		<?php
		foreach ($types as $number => $type)
		{
			if ($number % 2 == 0)
			{
			?>
		<tr>
		<?php
			}
		?>
		
			<td  style="vertical-align:top; text-align:right" width="68"><font face="Comic Sans MS" color="#FF9900"><?=$type?>:</font></td>
			<td>
		
		<?php
		for ($i=0;$i<$count;++$i)
		{
			if ($signupsheet[$type][$i])
			{
		?>
		<font face="Comic Sans MS"><?=$signupsheet[$type][$i]?></font><br>
		<?php
				
			}
			else
			{
				$inputavailable=true;
				
		?>
		
			
	<font color="#FF9900">
	<input type="text" name="<?=$type."_".$i?>"size="20" size="20" size="25"></font><br>
		<?php
			}
		}
		?>
		</td>
		<?php
			if ($number %2 != 0)
			{
		?>
		</tr>
		<?php
		}
		}
		?>
	</table>
	
  <p><font face="Comic Sans MS" color="#FF9900">If signing up for drinks, please 
    bring two 2-liters. Thank you.</font></p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	&nbsp; 
	<?php
	if($inputavailable)
	{
	?>
	<input type="submit" value="Submit"><input type="reset" value="Reset" name="B2">
	<?php
	}
	?></p>
</form>

</body>

</html>

Conditional for count.

Posted: Wed Oct 04, 2006 3:10 pm
by churt
Have you tried somthing like the following?


foreach ($types as $number => $type)
{
if ($number % 2 == 0)
{
?>
<tr>
<?php
}
?>

<td style="vertical-align:top; text-align:right" width="68"><font face="Comic Sans MS" color="#FF9900"><?=$type?>:</font></td>
<td>

<?php
if ($type=='Drinks'){$count=4; }else{ $count=8; }
for ($i=0;$i<$count;++$i)
{
if ($signupsheet[$type][$i])
{

Posted: Wed Oct 04, 2006 3:13 pm
by Luke
use php tags!! :x :evil:

Posted: Wed Oct 04, 2006 3:26 pm
by PaulD233
That worked. Thank you so much!