Displaying results based on radio selection in php5

hi,

i have some code that works fine in php4, but i can’t get it to work in php5…any help would be greatly appreciated.


if (isset($_POST['submit'])) { 
  $hidden = $_POST['hidden'];
 }
 
  if ($hidden == '1') 
  { 
   $viewHidden = '1'; 
  } 
  else  
  { 
    $viewHidden = '0'; 
	
	}

$query = "SELECT p.product_id, p.product_name, p.product_size, p.product_price, p.max_allowed, p.vendor_id as vid, v.vendor_id as id, v.vendor_name FROM products AS p LEFT JOIN vendor AS v ON (p.vendor_id=v.vendor_id)
          WHERE hidden='$viewHidden' order by product_name LIMIT $from, $max_results";

	
<form name="frmview" method="post" action="productslist.php">
   <input type="hidden" name="product_id" value="<?=$id?>" />


   <label>
 <input type="radio" name="hidden" value="0" <?php if(!$hidden) echo " checked=\\"checked\\""; ?> onClick="document.forms.frmview.submit()"/> List Active </label>
   <label><input type="radio" name="hidden" value="1" <?php if($hidden) echo " checked=\\"checked\\""; ?> onClick="document.forms.frmview.submit()"/> List Hidden</label>

  </form>

Thanks Raju! Works perfectly!

I don’t see anything in your code that will not run with PHP 5. Try to analyze the following form and PHP code specially naming the form elements (radio buttons and i have added another hidden field).


<?php
if (isset($_POST['btnSubmit'])) {
    $viewHidden = ($_POST['rdoStatus'] == 1) ? 1 : 0;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta name="author" content="Raju Gautam" />
	<title>Test</title>
</head>
<body>
    <form name="frmview" id="frmview" method="post" action="">
        <input type="hidden" name="product_id" value="<?php echo isset($id) ? $id : 0; ?>" />
        <input type="hidden" name="btnSubmit" value="1" />
        <label>
            <input type="radio" name="rdoStatus" value="0" <?php if(!$viewHidden) echo " checked=\\"checked\\""; ?> onclick="document.frmview.submit();"/> List Active
        </label>
        <label>
            <input type="radio" name="rdoStatus" value="1" <?php if($viewHidden) echo " checked=\\"checked\\""; ?> onclick="document.frmview.submit();"/> List Hidden
        </label>
    </form>
</body>
</html>

Then which part of your code is not working? Aren’t radio buttons that supposed to be selected/checked are not so? Or something else?

sorry…i should’ve said the radio button is not working…it is set to List Active but when i click on the List Hidden radio it goes right back to List Active.

What it is supposed to do and what it is not working in PHP 5? Which part of code is not working?

Try once:


if (isset($_POST['submit'])) { 
    $hidden = $_POST['hidden'];
}

if (isset($hidden)){ 
    $viewHidden = 1; 
}
else{
    $viewHidden = 0;
}

‘0’ might have been taken as a valid string and if(!$hidden) this is working as expected.

Edit:
Also I saw that you are using short tag in one of the hidden field which might also be the problem if short tag is OFF in php.ini which is default. But that is not related to radio buttons though.

it’s a form with radio buttons where users can select active or hidden products to display. based on the selection they make, it passes the hidden value to the query. thanks, but that didn’t work either.