Click to See Complete Forum and Search --> : [RESOLVED] Form doesn't go anywhere since switching to PHP5


tjbarr
09-20-2005, 07:04 PM
<?php
session_start();
include("../dbconn2.php");
function sesreg($sesname)
{
if(!session_is_registered($sesname))
{
session_register($sesname);
}
}
function buildOption($name,$value,$match)
{
if($match == $value)
{
$option="<option value=\"".$value."\" selected=\"selected\">".$name."</option>";
echo $option;
}
else
{
$option="<option value=\"".$value."\">".$name."</option>";
echo $option;
}
}
sesreg("sortby");
sesreg("county");
sesreg("county2");
sesreg("orgfunction");
sesreg("visited");
sesreg("displayType");


if($_SESSION['visited']==""){
$_SESSION['visited'] = "n";
}
if($_POST['submit'] == "")
$_SESSION['submit'] = "n";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel=stylesheet href="style.css" type="text/css">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style2 {
font-family: Helvetica, sans-serif;
font-size: xx-small;
}
-->
</style>
</head>

<body bgcolor="#006666">
<table width="100%" height="100%" cellpadding="5" cellspacing="1">
<tr bgcolor="#CCFFCC">
<td height="113" colspan="3" bgcolor="#CCFFCC"><img src="fedbanner.gif" width="587" height="101" align="left"><a href="map.html"><img src="map.gif" title="Search by County" alt="Search by County" width="96" height="103" border="0" align="right"></a></td>
</tr>
<tr>
<td height="2" colspan="3">
<p><a class="menu" href="/fed_dir/index.php">&nbsp;Home&nbsp;&nbsp;&nbsp;&nbsp;</a><a class="menu" href="resources.htm">&nbsp;&nbsp;&nbsp;&nbsp;Resources&nbsp;&nbsp;&nbsp;&nbsp;</a><a class="menu" href="glossary.html">&nbsp;&nbsp;&nbsp;&nbsp;Glossary
&nbsp;&nbsp;&nbsp;&nbsp;</a><a class="menu" href="mission.htm">&nbsp;&nbsp;&nbsp;&nbsp;About Us&nbsp;&nbsp;&nbsp;&nbsp;</a><a class="menu"
target="_blank" href="http://www.clevelandfed.org/CommAffairs/FinancialLit/PDF/FinSurvey3.pdf">&nbsp;&nbsp;&nbsp;&nbsp;Add Your Organization&nbsp;&nbsp;&nbsp;&nbsp;</a><a class="menu" href="disclaimer.htm">&nbsp;&nbsp;&nbsp;&nbsp;Disclaimer&nbsp;</a></p></td>
</tr>

<?php
if($_SESSION['visited']=="n" || $_SESSION['visited']=="")
{
?>


<form action= "<?php echo $_SERVER['PHP_SELF'];?>" method="POST">

<?php

$query3=<<<Q3
select * from tbl_fed_counties ORDER BY counties;
Q3;
$res_y = pg_query($conn,$query3);
$rows = pg_num_rows($res_y);
//echo $rows;
?>


<tr>
<td width="50%" rowspan="2" valign="top" bgcolor="#FFFFFF">
<h2> Welcome to the Ohio Financial Education Directory for Northern and Central Ohio</h2>
<p align="justify" class="main"> The goal of this site is to help you find financial education programs throughout northern and central Ohio. The site also provides general information about financial literacy including a <a href="glossary.html">glossary of terms</a> and links to <a href="resources.htm">resources</a>.


If you have a specific concern, it may be best to
search by program type.&nbsp; First select a program type and then select the
county you want to search.&nbsp; If you are interested in finding out what
programs and services are available in your area &ndash; start by holding down the shift key and choosing every entry from the listbox under program
types and then choose a county.&nbsp; For an alphabetical list of all
organizations in the directory - select "Display by Organization". <br>
</p>
</td>


<td width="50%" colspan="2" align="left" valign="top" bgcolor="#FFFFFF">
<h2>Directory by type of Program:</h2>
<h3 class="main"><strong>Select a type of program from the following list: </strong></h3>
</p>
<h5 align="left" class="main"> Hold shift key for multiple choices:</h5>
<h5 align="left" class="main"><a href="programs.htm" class="main ">Type of Program </a><br>
<br>
<select name="orgfunction[]" size="4" multiple>
<?php

buildOption("Saving/Investing/Wealth Building","issaving");
buildOption("Credit/Budgeting","iscredit");
buildOption("Abusive Credit Practices/Predatory Lending Education","ispredatory");
buildOption("Financing a Major Purchase","isfinancing");

?>
</select>
<br>
<br>
Now select a county to see which organizations offer the program in
that area. <br>
<select name ="county2[]">
<?php
for($row=0;$row < $rows;$row++)
{
$resulty=pg_fetch_assoc($res_y);
buildOption($resulty['counties'],$resulty['county_id']);
}


?>
</select> </h5>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#FFFFFF"><span class="main">
<input name="Submit" type="submit" value="Display by Program">
</span>

<td align="left" valign="top" bgcolor="#FFFFFF"><span class="main">
<input name="Submit" type="submit" value="Display by Organization">
</span>
</tr>
<tr align="center" valign="top" bgcolor="#FFFFFF">
<td height="2" colspan="3">
<div align="center">
<h6><span class="style2">&copy;2004 The Northern and Central Ohio Partnership for Financial Education<br>
~ <a href="mailto:tammy@urban.csuohio.edu">Technical Questions?</a> ~ <a href="mailto:maria.j.thompson@clev.frb.org">Content Questions?</a> </span></h6>
</div></td>
</tr>

<?php
$_SESSION['visited']= 'y';
}
else
{
$_SESSION = $_POST;
header("Location: displayfed.php");
}
?>

</form>
</table>



</body>

</html>

Weedpacket
09-20-2005, 07:26 PM
Read the Cautions and important notes on the session_register page. Those might give you a few pointers.

tjbarr
09-21-2005, 10:47 AM
Thanks, but I am still lost. I am pretty sure that our global variables were turned off in php4 as well as php5. Not sure how to use the $_SESSION. Is this what I need to change? In every instance of sesreg?

tjbarr
09-21-2005, 11:56 AM
Is this snippet from the above code correct? Its not redirecting to this page when the submit button is clicked.


{
$_SESSION = $_POST;
header("Location: displayfed.php");
}
?>

tjbarr
09-21-2005, 02:44 PM
I'm getting an error that says that I am missing variable 3 in buildOption(); Could it be that the select boxes are reading the choices?

Weedpacket
09-21-2005, 09:05 PM
Not sure how to use the $_SESSION.Read up on how to use PHP's session handling.

Oh, so you are getting an error message.

function buildOption($name,$value,$match) So the function expects to be passed three variables.

buildOption("Saving/Investing/Wealth Building","issaving"); But you're only passing it two.

This code wouldn't have worked even in PHP 4.

tjbarr
09-22-2005, 12:53 PM
Yes, thanks, I removed the third variable from that function, because it wasn't needed. Now I am not sure how to change the session_register call. I know it should be $_SESSION, but I try different things and get a blank page. Then when I think I have the session_regisiter correct - I am not redirecting to the second page displayfed.php - I just come back to this page after pressing submit.

tjbarr
09-22-2005, 03:57 PM
Any Help on the proper syntax to register the Session would be greatly appreciated.

Weedpacket
09-22-2005, 09:11 PM
Any Help on the proper syntax to register the Session would be greatly appreciated.

Excerpted from the session_register page.
<?php
// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet.";
?>

tjbarr
09-23-2005, 01:11 PM
O.k. I think I finally am getting it. I want to set two session variables equal to my select box arrays. What would the syntax be?

$_SESSION['county2']=????

Would it be the results from the resulty for loop in my code?

Now select a county to see which organizations offer the program in
that area. <br>
<select name ="county2[]">
<?php
for($row=0;$row < $rows;$row++)
{
$resulty=pg_fetch_assoc($res_y);
buildOption($resulty['counties'],$resulty['county_id']);
}


so maybe $_SESSION['county2']=$res2;?

tjbarr
09-23-2005, 03:00 PM
<?php
$_SESSION['visited']= 'y';
}
else
{
$_SESSION = $_POST;
header("Location: displayfed.php");
}
$_SESSION['county2']=$_POST[county2];
$_SESSION['orgfunction']=$_POST[orgfunction];


Used this code to make the session equal to my checkbox. Thanks for all the help