Page 1 of 1

now....select form help

Posted: Tue Jun 28, 2005 4:00 am
by pleigh
i am not really sure about this code if this will write correctly in my db

Code: Select all

//check for category of organization
	if (($_POST['category1'] > 0) OR ($_POST['category2'] > 0) OR ($_POST['category3']) >0)
	{
		$c = true;
	}
	else
	{
		$c = false;
		$message .= 'Please select at least 1 category<br>';
	}
the idea is that i have three options in my dropdown list, when the user selects the a category, it will write to the db the category he selects, and if the user don't select any...he will be prompted to select at least one...

Posted: Tue Jun 28, 2005 5:37 am
by djot
-
Hi,

I guess your select box is for selecting one option only?

Code: Select all

&lt;select name=&quote;category&quote;&gt;
&lt;option value=&quote;category1&quote;&gt;cat1&lt;/option&gt;
&lt;option value=&quote;category2&quote;&gt;cat2&lt;/option&gt;
&lt;option value=&quote;category3&quote;&gt;cat3&lt;/option&gt;
&lt;/select&gt;

if selected, $_POST['category'] will hold one of the values.

Code: Select all

// set $c to FALSE generally or manually inside the if
$c=FALSE;

// allowed user input
$allowed_categories = ARRAY('category1', 'category2', 'category3');

if (!isset($_POST['category']))
{
  //$c=FALSE;
  $message .= 'Please select at least 1 category<br>';
}
else
{
  // always check user input
  if (!in_array($allowed_categories))
  {
    //$c=FALSE;
    $message .= 'possible hack<br>';
  }
  else
  {
    $c=TRUE;
    $chosen = $_POST['category'];
  }
}