Page 1 of 1

Code worked in PHP4 but not in PHP5 _Problem with SESSIONS

Posted: Thu Sep 22, 2005 2:53 pm
by tjbarr63
feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php
session_start();   
 include("../dbconn2.php");
 function sesreg($sesname)
 {
 	if(!session_is_registered($sesname))
 	{
   		session_register($sesname);
 	}
 }
function buildOption($name,$value)
 {
   	$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
$query2=<<<Q2
	select * from tbl_fed_counties ORDER BY counties; 
Q2;
$res_x = pg_query($conn,$query2);
$rows = pg_num_rows($res_x);
//echo $rows;
$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">
    </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">
            </div></td>
  </tr>

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

</form>
</table>



</body>

</html>

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Sep 22, 2005 3:15 pm
by feyd
session_register() is a no-no. It is and was intended for register_globals being on (legacy stuff)


it'd help if you explained it a bit more than a somewhat cryptic topic title... :?

Posted: Thu Sep 22, 2005 3:55 pm
by tjbarr63
Sorry about the code. The problem is I can't figure out the correct syntax to register the sessions. if not session_register than how do you register the sessions? When I press submit it doesn't redirect to my answer page because "I think" it doesn't recognize that a session is started. If I could see a simple example of a session with a select box variable sent to another page it would help significantly.

Posted: Thu Sep 22, 2005 4:04 pm
by feyd
you can lose the sessreg function altogether..

Code: Select all

session_start();
$_SESSION['foo'] = 'bar';
that "registers" foo with the string 'bar'.

Posted: Fri Sep 23, 2005 11:12 am
by tjbarr63
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Thanks!!!  One more question How would I make the $_SESSION['county2']= to the results from my select box?

Code: Select all

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']); 
}
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Sep 23, 2005 12:01 pm
by feyd
assuming you are using method post

Code: Select all

$_SESSION['country2'] = $_POST['country2'];

Posted: Fri Sep 23, 2005 12:19 pm
by pilau
I'd recommend to go here and read the part about sessions, and the $_SESSION variable.
Believe me, it'll open your eyes.

Resolved

Posted: Fri Sep 23, 2005 12:58 pm
by tjbarr63
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php
 $_SESSION['visited']= 'y';
}
else
{
	$_SESSION = $_POST;
	header("Location: displayfed.php");
 }
 $_SESSION['county2']=$_POST[county2];
$_SESSION['orgfunction']=$_POST[orgfunction];
?>
Thanks, I looked at the manual that you suggested and it did open my eyes. Thanks Much
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Sep 23, 2005 1:02 pm
by pilau
Hey, 'tis be why we're here, me heartie!