Jump to content

[SOLVED] Adding items to a form


The Midnighter

Recommended Posts

Ok, so basically.. I thought this was the most simple way of doing this, but its turning out to be a bit of trouble.

 

I can see what I'm doing wrong, Im' just having a brain fart and cannot think of the proper way to do this.. I realize that $current is never going to catch up to $snom at this point..

 

I have a form, and I am simply trying to add more than one text area, by doing the following:

 

 

 

$snom = $_GET['snum'];
   if (!$snom) { $snom = "1"; $current = "0"; } // If it's not declared yet, declare it..
   else if ($snom == "1") { $current = "0"; } // To at least one field
   else { $current = $snom-1; } // Else add one

 

Then to write it:

 

while ($current != $snum ) 
{ 
echo "<input name=\"serial\" id=\"serial\" type=\"text\" size=\"40\" />"; 
$current++; 
} 
?>

<a href="index.php?snum=<?php echo $snum+1; ?>">Add item</a>

Link to comment
https://forums.phpfreaks.com/topic/159854-solved-adding-items-to-a-form/
Share on other sites

Solved, had my logic backwards:

 

$current = "0";
$snom = $_REQUEST['snum'];
   if (!$snom || $snom == "0") { $snom = "1"; }

To record,

 

<?php echo ('Current = ' . $current .' Snom = ' . $snom);
	  while ($current < $snom ) { echo "<input name=\"serial\" id=\"serial\" type=\"text\" size=\"40\" />"; $current++; } ?><a href="index.php?snum=<?php echo $snom+1; ?>">Add item</a>

 

To use.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.