Jump to content


Photo

Please, Help me.. ( Sessions ) !


  • Please log in to reply
12 replies to this topic

#1 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 02 August 2006 - 11:07 AM


Hello  :)

I have two files.. form.php  -  query.php

form.php

	<form action="http://localhost/queries/query.php" method="post" name="form">
	
	Searching for players which play these games...
	<br />
	<br />
		 <input name="football" type="checkbox" value="x">Football
		 <br />
		 <input name="basketball" type="checkbox" value="x">Basketball
	<br />
	<br />
	<input name="reset" type="reset" value="Reset"/>
	<input name="submit" type="submit" value="Submit"/>			
	
	</form>

query.php

<?php
$page=$_GET["page"];
if(!isset($page))
{
	$page=1;
	$pageNo = $page +1;
}

$pageNo = $page;
echo "Page Number:&nbsp<b>$pageNo</b>";

$page=$page-1;

//connecting to my database.. and for sure it's working..(hidden for now)
//....
//....
//....

$football = $_POST['football'];
$basketball = $_POST['basketball'];

$preQuery="select * from Macrofossiles where (football = '$football') || (basketball= '$basketball')";
$preResult=mysql_query($preQuery,$server) or die("Could not execute preQuery...");
$numRows=mysql_num_rows($preResult);
$numPages=$numRows/1;

$query = "select * from Macrofossiles where (football = '$football') || (basketball= '$basketball') limit $page, 1"; 
$result = mysql_query($query,$server) or die("Could not execute query..."); 

while($row = mysql_fetch_array($result))
{
    echo 
		 '<table bordercolor="#CC7722" align="center">' .
		 "<tr><td>Player Number:</td><td>{$row['Player_No']}</td></tr>" .
		 "<tr><td>Hockey:</td><td>{$row['Hockey']}</td></tr>" .
		 "<tr><td>Volleyball:</td><td>{$row['volleyball']}</td></tr>" .
		 "<tr><td>Tennis:</td><td>{$row['tennis']}</td></tr>" .
		 "<tr><td>Football:</td><td>{$row['football']}</td></tr>" .
       "<tr><td>Basketball:</td><td>{$row['Basketball']}</td></tr>" .
		 "</table>";
}	   
	   echo "<b>Page:</b>&nbsp;&nbsp";
	   
	   $num=1;	   
	   for($i=1;$i<$numPages;$i++)
	   {
		if($num==$pageNo)
		{
			$font="<b>";
			$unfont="</b>";
		} 
		else 
		{
			$font="";
			$unfont="";
		}
	    echo "<a href='query.php?page=$num'>$font $num $unfont</a>&nbsp";
	    $num = $num + 1;
	  }	

mysql_close($server); 
?>

Database:

|  Player_No  |  Hockey  |  Volleyball  |  Tennis  |  Football  |  basketball  |
|      1        |      x      |      x      |            |      x      |                |
|      2        |              |      x      |      x      |              |        x        |
|      3        |      x      |              |      x      |      x      |                |
|      4        |              |      x      |      x      |              |        x        |
|      5        |      x      |      x      |            |      x      |        x        |
|      6        |      x      |      x      |            |      x      |                |
|      7        |              |      x      |      x      |              |        x        |
|      8        |      x      |              |      x      |      x      |                |
|      9        |              |      x      |      x      |              |        x        |
. . . etc

I hope someone can help..

Oops.. I didn't tell you guys what is the problem I'm sufferring from in these codes..

here is it..

when I check the two checkboxes... and click submit..

the query.php open and everything seems okey.. the results are perfect.. and exact..

but !! .. when I click page number 2 or 3 or any number after the first click, everything is changed !! ..

it geves me the result of this query
"select * from Macrofossiles where (football = '') || (basketball= '')"

I mean it gives me the result when football is empty and basketball is empty..

that means this query-->"select * from Macrofossiles" all the resutls will show up ..  :(

it seems to me that I need to write sessions..

but how that will ! .. what should I write and where in my code !!

any help !  ::)  :D


#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 11:51 AM

SO your using sessions?
Do you have session_start();
on line 1 of your code?
Tell me the problem, I will try tell you the solution

#3 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 02 August 2006 - 12:34 PM

I just started adding the session stuff.. ;D

now.. I have this code in both files.. the form and the query..

<?php
session_start();
..............................etc


but I got an error..

in my two files..

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Documents and Settings\Work Station\Desktop\wamp\www\WebSite\forms\form1.php:9) in C:\Documents and Settings\Work Station\Desktop\wamp\www\WebSite\forms\form1.php on line 61

on line 9 there is a usual meta tag
on line 61 there is session_start();

so ! what is the problem !!


#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 01:10 PM

session_start() needs to be on line 1
Before <html>
As it sends html headers

and should only be on line 1, not duplicated
Tell me the problem, I will try tell you the solution

#5 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 02 August 2006 - 01:45 PM


Oh I really appreciate your help.. thanks alot..

now.. what about the variables !! ?

can I do this:

form.php

...etc

<input name="<?php $ostracodes='ostracodes'; ?>" type="checkbox" value="x">Ostracodes
<input name="<?php $indetermine='indetermine'; ?>" type="checkbox" value="x">Indetermine

...etc

</form>

<?php
$_SESSION['ostracodes'] = $ostracodes;
$_SESSION['indetermine'] = $indetermine;
?>


#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 02:01 PM

wha, no

<input type='checkbox' name='Ostracodes' value='x'>Ostracodes

then

if($_POST["Ostracodes"] == "x"){
$_SESSION["ostracodes"] = "x";
}
Tell me the problem, I will try tell you the solution

#7 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 02 August 2006 - 02:27 PM


Okay  :)

I wrote in my form.php


............etc

<input name="ostracodes" type="checkbox" value="x">Ostracodes
<br />
<input name="indéterminé" type="checkbox" value="x">Indéterminé
<br />
<br />
<input name="reset" type="reset" value="Reset"/>
<input name="submit" type="submit" value="Submit"/>		
</form>
<?php
if($_POST['ostracodes'] == 'x') $_SESSION['ostracodes'] = x;
if($_POST['indetermine'] == 'x') $_SESSION['indetermine'] = x;
?>

............etc


now ! .. in my query.php

should I do this:

<?php
............etc

$ostracodes = $_SESSION['ostracodes'];
$indetermine = $_SESSION['indetermine'];

$preQuery="select * from Macrofossiles where (ostracodes = '$ostracodes') || (indetermine = '$indetermine')";

............etc
?>


#8 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 02 August 2006 - 02:46 PM


I figured out that I should write these

<?php
if($_POST['ostracodes'] == 'x') $_SESSION['ostracodes'] = x;
if($_POST['indetermine'] == 'x') $_SESSION['indetermine'] = x;
?>

in my query.php  not  my form.php


I wrote them in this way:

<?php
if(isset ($_POST['ostracodes'])) 
      {$_SESSION['ostracodes'] = x;}
	
if(isset ($_POST['indetermine'])) 
      {$_SESSION['indetermine'] = x;}
?>



#9 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 02 August 2006 - 02:48 PM


but still ! .. should I write these lines of code in my query.php ??


<?php
............etc

$ostracodes = $_SESSION['ostracodes'];
$indetermine = $_SESSION['indetermine'];

$preQuery="select * from Macrofossiles where (ostracodes = '$ostracodes') || (indetermine = '$indetermine')";

............etc
?>


#10 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 03 August 2006 - 03:55 PM


as I'm taking info from my database and showing it in many pages..

is it right to do this.. for passing variables to the another page ?


<?php
$num=1;	   
for($i=1;$i<$numPages;$i++)
{	   
	if($num==$pageNo)
		{
			$font="<b>";
			$unfont="</b>";
		} 
		else 
		{
			$font="";
			$unfont="";
		}
echo "<a href='query1.php?page=$num&tennis=$_SESSION['tennis']&basketball=$_SESSION['basketball']'>$font $num $unfont</a>&nbsp";
	    $num = $num + 1;
}	
?>


My question is mostly for this part ( sessions )

<?php

echo "<a href='query1.php?page=$num&tennis=$_SESSION['tennis']&basketball=$_SESSION['basketball']'>$font $num $unfont</a>&nbsp";

?>


#11 web designer

web designer
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 03 August 2006 - 04:12 PM


Oh :( I think what I have written above is wrong  :-\

please can any one help ?  :-[

I don't know why is the session not working !!


#12 dottedquad

dottedquad
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 August 2006 - 04:18 PM


Oh :( I think what I have written above is wrong  :-\

please can any one help ?  :-[

I don't know why is the session not working !!


try reading the sessions in the FAQ: http://www.phpfreaks...ic,31047.0.html

#13 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 03 August 2006 - 04:24 PM

If you set your variables in a session, you don't need to pass them in a URL as well.

Instead of trying to get your variable from $_POST, then assigning them to $_SESSION, followed by moving them to $_GET, just change your search form to use the $_GET method and keep it that way, like so:

form.php
<form action="http://localhost/queries/query.php" method="GET" name="form">
	
	Searching for players which play these games...
	<br />
	<br />
		<input name="football" type="checkbox" value="x">Football
		<br />
		<input name="basketball" type="checkbox" value="x">Basketball
	<br />
	<br />
	<input name="reset" type="reset" value="Reset"/>
	<input name="submit" type="submit" value="Submit"/>			
	
	</form>

query.php
<?php
$page=$_GET["page"];
if(!isset($page))
{
	$page=1;
	$pageNo = $page +1;
}

$pageNo = $page;
echo "Page Number:&nbsp<b>$pageNo</b>";

$page=$page-1;

//connecting to my database.. and for sure it's working..(hidden for now)
//....
//....
//....

$football = $_GET['football'];
$basketball = $_GET['basketball'];

// YOUR QUERIES AND RESULT PRINTING
...
...

// YOUR URL TO THE NEXT PAGE OF RESULTS

echo "<a href='query.php?page=$pageNo&football=$football&basketball=$basketball'>$font $num $unfont</a>&nbsp";

// YOUR MySQL SESSION CLOSING, ETC...
...
...
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users