I'm a NEWBIE and I have been stuck on this for days.

I have one table that has the following rows:

rid = Referral ID
category = Category
subcategory = Subcategory
rbusiness = Referred Business Name
rcontact = Referred Contact Name
etc..

I have created the form (referral_input.php) that allows the user to input their referral data including category and subcategory. I have also created a page (my_categories.php) which lists all the categories in which the user has a referral using a WHILE LOOP. From there, I wish for the user to select one of their categories and then be taken to (my_subcategories.php) where I employ another WHILE LOOP. From there, the user would select a subcategory and be taken to a resulting page displaying all the date for that referral (like a contact page in address book).

So here is where I am stuck. I have tried many variations (from $_POST to $GET to SESSION) to pass along the value of their selection on the (my_categories.php) to the (my_subcategories.php) page and include it in the query. None have worked. Any advice and patience is welcome. Also, as I am new, please be descriptive. I see many responses that are one sentence long and mean nothing to those of us starting out.

Here are the pages:

1st page (my_categories.php)

<?php
include "include/session.php";
include "fb-config.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
		<title>friendhelper</title>
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="index,follow" name="robots" />
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<link href="http://www.friendhelper.com/css/style.css" rel="stylesheet" media="screen" type="text/css" />
		<script src="http://www.friendhelper.com/javascript/functions.js" type="text/javascript"></script>
		<meta content="iPad,iPhone,iPhone4,referrals,friends,networking,app" name="keywords" />
		<meta content="socially give and receive referrals with friends for products and services with this add" />
	</head>
	<body>
		<div id="topbar">
			<div id="leftnav"><a href="home.php"><img alt="home" src="images/home.png" /></a><a href="friends.html">Friends</a></div>
			</div>
			<div id="rightnav"><a href="page-coming-soon.php">Friend Request</a></div>
		<div id="content">

			<ul class="pageitem">
			<li class="menu"> <a class="noeffect" onclick="location.href='referral_input.php'"> <img alt="my account" src="http://friendhelper.com/thumbs/myaccount-thumb.png" /><span class="name">Add a Referral</span><span class="arrow"></span></a></li>
			</ul>
			<span class="graytitle">My Categories</span>
			<form method='POST'  name="mycategories" action='my_subcategories.php'>
				<fieldset>
					<ul class="pageitem">
	<?php	$query = "SELECT * FROM referrals WHERE username='$_SESSION[username]' ORDER BY category ASC"; 
			$result = mysql_query($query) or die(mysql_error());
			while($row = mysql_fetch_array($result)){ ?>		
						<li class='menu'><span class='name'>
						<a class="noeffect"  onclick="document.mycategories.submit();return false" />
						<input type="hidden" name="category">
<?php	echo $row['category']; ?>
						</span><span class='arrow'></span></a></li>
<?php	echo "";	} ?>
					</ul>
				</fieldset>
			</form>
		</div>
	</body>
</html>

2nd page (my_subcategories.php)

<?php
include "include/session.php";
include "fb-config.php";

$category=$_POST['category'];
$category=mysql_real_escape_string($category);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
		<title>friendhelper</title>
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="index,follow" name="robots" />
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<link href="http://www.friendhelper.com/css/style.css" rel="stylesheet" media="screen" type="text/css" />
		<script src="http://www.friendhelper.com/javascript/functions.js" type="text/javascript"></script>
		<meta content="iPad,iPhone,iPhone4,referrals,friends,networking,app" name="keywords" />
		<meta content="socially give and receive referrals with friends for products and services with this add" />
	</head>
	<body>
		<div id="topbar">
			<div id="leftnav"><a href="home.php"><img alt="home" src="images/home.png" /></a><a href="friends.html">Friends</a></div>
			</div>
			<div id="rightnav"><a href="page-coming-soon.php">Friend Request</a></div>
		<div id="content">

			<ul class="pageitem">
			<li class="menu"> <a class="noeffect" onclick="location.href='referral_input.php'"> <img alt="my account" src="http://friendhelper.com/thumbs/myaccount-thumb.png" /><span class="name">Add a Referral</span><span class="arrow"></span></a></li>
			</ul>
			<span class="graytitle">My SubCategories</span>
			<form method='POST'  name="mycategories" action='my_subcategories.php'>
				<fieldset>
					<ul class="pageitem">
	<?php	$query = "SELECT * FROM referrals WHERE username='$_SESSION[username]' AND category='$category' ORDER BY subcategory ASC"; 
			$result = mysql_query($query) or die(mysql_error());
			while($row = mysql_fetch_array($result)){ ?>		
						<li class='menu'><span class='name'>
						<a class="noeffect"  onclick="document.mycategories.submit();return false" />
						<input type="hidden" name="subcategory">
	<?php		echo $row['subcategory']; ?>
						</span><span class='arrow'></span></a></li>
	<?php	echo "";	} ?>
					</ul>
				</fieldset>
			</form>
		</div>
	</body>
</html>

The Problem is you need to echo the variables $row in the first page and $row in the second page inside the hidden input as a value of this input

like this for the first page

<input type="hidden" name="category" value="<?php echo $row['category']; ?>">

and this for the second page

<input type="hidden" name="subcategory" value="<?php echo $row['subcategory']; ?>">

Because $_POST global is actually accessing the VALUE of the field when the form is submitted , so if the value of the input is not defined
the $_POST will be NULL and that what exactly happened for you.

First of all enclose your code inside CODE tag....

My first post to this forum and I have to say that I am very impressed with the time and helpfulness. Thanks AMR87, I should have posted this inquiry days ago.

IIM, I am such a NEWBIE that I am going to have to Google exactly what you mean by "enclose your code inside CODE tag…"

what IIM meant is to put the code for your problem inside code tag by selecting your code and pressing in code icon appears in the post box in this thread , so the code will be easy to view and debug
and you are welcome, if the solution worked for you , plz mark the thread as solved

<ul class="pageitem">
<?php $query = "SELECT DISTINCT category FROM referrals WHERE username='$_SESSION[username]' ORDER BY category ASC"; 
	$result = mysql_query($query) or die(mysql_error());
	while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
?>		
		<li class='menu'><span class='name'>
		<a class="noeffect"  onclick="document.mycategories.submit();return false" />
		<input type="hidden" name="catsel" value="<?php echo $row['category']; ?>">

<?php echo $row['category']; ?>
		</span><span class='arrow'></span></a></li>
<?php echo "";	} ?>
		</ul>

On the second page… ( $catsel=$_POST; $catsel=mysql_real_escape_string($catsel); ) but the returned values are the subcategories of the last loop, regardless of which loop I select.

If I select:

Baby - Child, the next page displays the sub-categories "Apparel-Clothing" and "Games-Toys" which is correct.

Auto-Car, the next page displays the sub-categories "Apparel-Clothing" and "Games-Toys" which is Incorrect.

Auto-Car selection should result in the categories "Insurance".

I know this has something to do with the code only reading the last loop regardless of the referencing value <?php echo $row; ?>

Any ideas on what I can include to POST the correct subcategories relative to the user's selection?

Try to use the mysql_num_rows for the query this query and see how many rows it gets

<?php
$query = "SELECT DISTINCT category FROM referrals WHERE username='$_SESSION[username]' ORDER BY category ASC";
$result = mysql_query($query) or die(mysql_error());
$numRows =mysql_num_rows($result);
echo "NUMBER OF ROWSC = ".$numRows;
?>

I just get "NUMBER OF ROWS = 2"

Can someone please help me so that the correct result of the users selection is displayed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.