Page 2 of 3

Posted: Mon Nov 06, 2006 12:37 pm
by RobertGonzalez
You might want to consider setting a $_SESSION['search_lname'] var and setting that to '' (empty). When there is something passed in the form as a search parameter, assign that session var to the search param so it stays with the paging routine (just make sure to not set up paging when the search term is null or you might end up pulling all 3 million records).

Posted: Mon Nov 06, 2006 3:47 pm
by sparky753
I was able to create the session variable to use in the next page... no error messages. But my query is not pulling the desired results for some reason.

Code: Select all

$query = "SELECT * from users WHERE LastName='{$_SESSION['lname']}';
It's just doing a Select * but not using the Where condition...

Posted: Mon Nov 06, 2006 4:03 pm
by RobertGonzalez
For error checking, do this...

Code: Select all

<?php
echo 'The sessioned last name is: ' . $_SESSION['lname'];
$query = "SELECT * from users WHERE LastName='" . $_SESSION['lname'] . "'";
?>

Posted: Mon Nov 06, 2006 4:58 pm
by sparky753
This is almost eerie - I just did that...I typed an echo statement on the original submitting page :) It seemed like it was generating the correct Last Name on that page but not any more - no names are getting printed. I put in an echo statement on the page that it is getting submitted to as well and the name isn't showing up there too.

Posted: Mon Nov 06, 2006 5:38 pm
by RobertGonzalez
Okay, post the code for the submitting page (where you echoe'd and where you saw that it was good) and then show the code for the assignment of the $_POST var to a $_SESSION var, then how it is called in the other pages. Let make sure they are all using the same variable.

Posted: Tue Nov 07, 2006 9:40 am
by sparky753
I thought i had it displaying correctly but it wasn't. Right now, my echo statements on both search4.php and search5.php are not displaying anything.

The following is my code on 'search4.php', the page that has the form/Search field. Even the "Hello" isn't printed on the screen so i know now that the else part of my code doesn't work:

Code: Select all

<?
	  	  if (!isset($_POST['submit'])) {
		  //do nothing
		  }
		  else {
		  
		  $_SESSION['PatientLastName'] = $_POST['PatientLastName'];
		  echo "Hello";
		  echo $_SESSION['PatientLastName'];
		  }
 	  ?>
On the page processing the form and running the queries 'search5.php', i access this session variable this way:

Code: Select all

$_SESSION['PatientLastName']
And in my queries on that page, i refer to it this way:

Code: Select all

$query = "SELECT * from users WHERE LastName='{$_SESSION['lname']}';
Should i do it the way you've suggested?

Code: Select all

$query = "SELECT * from users WHERE LastName='" . $_SESSION['lname'] . "'";

Posted: Tue Nov 07, 2006 10:01 am
by RobertGonzalez
Ok, post the form code (the html) and post the entire search4.php page code. Post it exactly how it is in your php file.

Posted: Tue Nov 07, 2006 10:38 am
by sparky753
search4.php:

Code: Select all

<?
	  	  echo "<center><a href='logout.php'> Logout </a></center>";
		  ?>   	      
      

     <form action="search5.php" method="post" >
       <p align="center">Search for User by Last Name</p>
       <p align="center">
         <input type="text" name="LastName"> 
		 <input type="hidden" name="test" value="test">
       </p>
       <p align="center">
         <input type="submit" name="submit" value="Search"> 
       </p>
      </form>
 
    
     <?
	  	  if (!isset($_POST['submit'])) {
		  //do nothing
		  }
		  else {
		  
		  $_SESSION['LastName'] = $_POST['LastName'];
		  echo "Hello";
		  echo $_SESSION['LastName'];
		  }
	  	  ?>
The form part alone is HTML...The rest of the HTML doesn't have any code of significance - just a table tag for the form.

Posted: Tue Nov 07, 2006 11:31 am
by RobertGonzalez
Sounds funny, but this could be a 'short tags' issue. Try using this code. Also, I see no call to session_start(). Where is that happening? It would really help to see all the code (we don't database details, but the complete code is always helpful in helping you).

Code: Select all

<?php
echo "<center><a href='logout.php'> Logout </a></center>";
?>         
     
<form action="search5.php" method="post" >
<p align="center">Search for User by Last Name</p>
<p align="center">
<input type="text" name="LastName">
<input type="hidden" name="test" value="test">
</p>
<p align="center">
<input type="submit" name="submit" value="Search">
</p>
</form>
 
<?php
if (!isset($_POST['submit'])) {
    //do nothing
} else {
    $_SESSION['LastName'] = $_POST['LastName'];
    echo "Hello";
    echo $_SESSION['LastName'];
}
?>

Posted: Tue Nov 07, 2006 12:48 pm
by sparky753
No problem. Sorry about that...

Code: Select all

<?
session_start();
include "include/db.php";


if (!isset($_SESSION['username']))
{ 
    print "not logged in";
	
    print "<script>";
    print " self.location='login.php';"; 
    print "</script>";
}

else
{ 
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>My Test</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<style type="text/css">
<!--
.style1 {
	font-size: 16px;
	font-weight: bold;
}

.input
{
    font-family:Verdana, Arial, Helvetica, sans-serif;
    font-size:12px;
}
.style2 {font-size: 12px}

-->
</style>
</head>
<body>


<table class="tmpl_brdrclr" width="100%" border="0" cellspacing="1" cellpadding="1"  summary=" " >
  <!--TABLE A - BIG-->
  <tr> 
    <td width="125" class="tmpl_sidebackgroundl" valign="top">&nbsp;</td>
    <!--Content Area Begins Here-->
    <td valign="top" colspan="2"> <p align="center" class="style1">Monitoring Program</p>
	  
             <?
	  	  echo "<center><a href='logout.php'> Logout </a></center>";
		  $display = 10;
	  	  ?>   	  
    
      <form action="search5.php" method="post" >
       <p align="center">Search for User by Last Name</p>
       <p align="center">
         <input type="text" name="LastName"> 
		 <input type="hidden" name="test" value="test">
       </p>
       <p align="center">
         <input type="submit" name="submit" value="Search"> 
       </p>
      </form>
 
         <?
	  	  if (!isset($_POST['submit'])) {
		  //do nothing
		  }
		  else {
		  
		  $_SESSION['LastName'] = $_POST['LastName'];
		  echo "Hello";
		  echo $_SESSION['LastName'];
		  }
	  	  ?> 
   		
	 
     </td>
    
    <td class="tmpl_sidebackgroundl"  width="158" valign="top" >&nbsp; </td>
  </tr>
</table>


<?
} // if session started
?>

</body>
</html>

Posted: Tue Nov 07, 2006 1:17 pm
by RobertGonzalez
Try changing the short PHP tags (<?) to regular PHP tags (<?php). See if that does anything. Also, instead of checking if the form is not submitted, why not check to see if it is (and do a print_r($_POST) just before you assign the session vars from post data).

Posted: Tue Nov 07, 2006 1:39 pm
by sparky753
I changed the tags to the regular PHP tags, changed the if statement to test if form is submitted rather than not submitted, added the print_r statement just before the session variable is assigned the post data...no luck though...

Posted: Tue Nov 07, 2006 1:57 pm
by RobertGonzalez
Next step, clear your browser cache. Also, what did the print_r display (the source, not what was on the screen).

Posted: Tue Nov 07, 2006 2:16 pm
by sparky753
I cleared the cache. The print_r statement's not doing anything. I inserted it just before assigning the post data to the session variable:

Code: Select all

<?php
	  	  if (isset($_POST['submit'])) {
		  print_r($_POST);
		  $_SESSION['PatientLastName'] = $_POST['PatientLastName'];
		  echo "Hello";
		  echo $_SESSION['PatientLastName'];
		 	}
		  else {
		   //do nothing
		  echo "Goodbye";
		   }
	  ?>
I've never worked with print_r - do we view the page source on submitting the form?

Posted: Tue Nov 07, 2006 2:37 pm
by RobertGonzalez
print_r() will show you a lot of information about your variable(s) that you put into it. If you are getting nothing on a print_r($_POST) then your form information is not sending.