Skormy
08-26-2007, 06:08 AM
This one's got me scratching my head. I've got a page which displays inventory which has worked fine for months. I'm in the process of adding a drop-down to allow visitors to view a subset of the inventory. The problem is once I've added the form, the original query doesn't execute upon display. I've tinkered with a couple of things, but am just baffled. Any insights will be appreciated.
Form Section:
<FORM NAME="sort" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<SELECT NAME="earcode"
<OPTION VALUE=""></option>
<OPTION VALUE="ALL" selected="selected">Display all Earrings </option>
<OPTION VALUE="E">Display only Earwire Earrings</option>
<OPTION VALUE="P">Display only Post Earrings</option>
<OPTION VALUE="L">Display only Lever back Earrings</option>
</SELECT>
<input type="submit" value="Display Selected Earrings">
</FORM>
A block that doesn't seem to make a difference:
if (isset($_REQUEST['submitted']) && $_REQUEST['submitted'] == '1') {
echo "Form submitted!";
}
Here's the standard query:
$query = "SELECT code, id,name,price,description
FROM dbtable WHERE status = 'A'
AND code = 'E'";
$result = mysql_query($query) or die('Query not successfully processed: ' . mysql_error());
Here's the logic block from the form. If I comment this out, the page query executes just fine.
// select dbquery
if ($earcode =="ALL")
$queryb = "SELECT code, id,name,price,description
FROM dbtable WHERE status = 'A'
AND code = 'E'";
else
$queryb = "SELECT code,id,name,price,description
FROM dbtable WHERE status = 'A'
AND cat_code = 'E'
AND ear_code = '$earcode'" ;
$result = mysql_query($queryb) or die('Query not successfully processed: ' . mysql_error());
Here's another block of code, pretty standard stuff:
$cols = mysql_num_fields( $result );
// get each row
while($row = mysql_fetch_row($result)) {
What am I missing here? Do I need completely separate paths? Are they tripping over shared variables? Do I need another branch on my IF?
Thanks in advance.
Form Section:
<FORM NAME="sort" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<SELECT NAME="earcode"
<OPTION VALUE=""></option>
<OPTION VALUE="ALL" selected="selected">Display all Earrings </option>
<OPTION VALUE="E">Display only Earwire Earrings</option>
<OPTION VALUE="P">Display only Post Earrings</option>
<OPTION VALUE="L">Display only Lever back Earrings</option>
</SELECT>
<input type="submit" value="Display Selected Earrings">
</FORM>
A block that doesn't seem to make a difference:
if (isset($_REQUEST['submitted']) && $_REQUEST['submitted'] == '1') {
echo "Form submitted!";
}
Here's the standard query:
$query = "SELECT code, id,name,price,description
FROM dbtable WHERE status = 'A'
AND code = 'E'";
$result = mysql_query($query) or die('Query not successfully processed: ' . mysql_error());
Here's the logic block from the form. If I comment this out, the page query executes just fine.
// select dbquery
if ($earcode =="ALL")
$queryb = "SELECT code, id,name,price,description
FROM dbtable WHERE status = 'A'
AND code = 'E'";
else
$queryb = "SELECT code,id,name,price,description
FROM dbtable WHERE status = 'A'
AND cat_code = 'E'
AND ear_code = '$earcode'" ;
$result = mysql_query($queryb) or die('Query not successfully processed: ' . mysql_error());
Here's another block of code, pretty standard stuff:
$cols = mysql_num_fields( $result );
// get each row
while($row = mysql_fetch_row($result)) {
What am I missing here? Do I need completely separate paths? Are they tripping over shared variables? Do I need another branch on my IF?
Thanks in advance.