Thanks for the replies. I tried the hidden field; no luck. I also tried changing the form to post to itself to echo the $agency_no field, but that didn't work, either. Not sure if I did that right, tho:
<body>
<? global $php_self;?>
<form method="post">
<input type=hidden name="a_no" value="<? echo $agency_no; ?>">
<input type="submit" name="save" value="View Information">
<?
echo "agency_number is".$agency_no;
?>
</form>
</body>
</html>
Lemme clarify a bit:
- There are actually four pages I'm using. This db allows users to get information on different businesses (agencies). The first page (page A) allows the user to enter part of the name. The second page (page 😎 queries the db, and decides if more than one record matches the query.
If only one record matches, it automatically goes to the fourth page (page2.php), queries the db, and displays appropriate info. That works fine.
If more than one record matches the query from page B, it goes to the third page (page1.php) and displays a drop down box listing the results of the query. The user then chooses one from the select box and hits the submit button. Then, in theory, the chosen $agency_no is passed to the fourth page (page2.php) and it queries the db and displays the appropriate info.
With the code below, I can't get the agency_no to print on the page, or when I change it to the commented html part, that doesn't work either. So even if the HTML to post to the same page is wrong, it doesn't work the other way, either.
page1.php
include ("contact_functions.php");
//name entered on previous page
$ag_name = $_GET['ag_name'];
connect();
$result = mysql_query ("select agency_no, agency_name from agency where agency_name like \"%$ag_name%\" order by agency_no");
$num_rows = mysql_num_rows ($result);
echo "<font face=\"Comic Sans MS, Tahoma\">";
echo "Your search resulted in more than one agency. Please select an agency from the list below: <BR></p>";
echo "<select name=\"agency_no\">";
while ($a_row = mysql_fetch_array($result))
{
$a_num = $a_row['agency_no'];
$a_name = $a_row['agency_name'];
$small_num = substr($a_num,0,4);
echo "<option value=\"".$a_num."\">".$small_num." - ".$a_name."</option>";
}
echo "</select></p>";
mysql_close ($link);
?>
<html>
<head>
<title>Agency Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#CCCCCC" text="#000099">
<? global $php_self;?>
<form method="post">
<!--<form method ="post" action="page2.php">-->
<input type=hidden name="a_no" value="<? echo $agency_no; ?>">
<input type="submit" name="save" value="View Information">
<?
echo "number is".$agency_no;
?>
</form>
</body>
</html>
page2.php
<?
// include system functions
include ("contact_functions.php");
//get number of agency to be displayed from either select_agency or search_agency
$info = $_POST['a_no'];
connect();
//query db for info
$result = mysql_query ("select agency_no, agency_name, website, ftes, rms, exempt, agency_comm from agency where agency_no = \"$info\"");
//name fields in query
$a_row = mysql_fetch_array($result);
$a_no = $a_row['agency_no'];
$a_name = $a_row['agency_name'];
$a_web = $a_row['website'];
$a_fte = $a_row['ftes'];
$a_rms = $a_row['rms'];
$a_exempt = $a_row['exempt'];
$a_comm = $a_row['agency_comm'];
?>
<html>
<head>
<title>Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#CCCCCC" text="#000099">
<p align="left"><font face="Comic Sans MS, Tahoma" size="5">
<?
$small_num = substr($a_no,0,4);
echo $small_num;
echo " - ";
echo $a_name;
?>
<b>
</font></b></p>
<p align="left"> </p>
<fieldset> <legend><font face="Comic Sans MS, Tahoma" size="4">General Agency Information:</font></legend>
<p align="left"><font face="Comic Sans MS, Tahoma">
</p>
Comments: <? echo $a_comm; ?></font></p>
</fieldset>
<p align="left"><font face="Comic Sans MS, Tahoma"><a href="main_menu.php">Return
to Main Menu</a></font></p>
<p align="left"> </p>
</body>
</html>
Thanks again for all the help. Since I'm the only one here at work learning PHP (the others use Java), this forum is a HUGE help!