Jump to content

Please, Help me.. ( Sessions ) !


web designer

Recommended Posts

[color=brown]
Hello  :)

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

[b]form.php[/b]
[/color]
[code]
<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>
[/code]
[color=brown]
[b]query.php[/b]
[/color]
[code]
<?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);
?>
[/code]
[color=brown]
[b]Database:[/b]

|  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[/color]
Link to comment
Share on other sites

[color=brown]I just started adding the session stuff.. ;D

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

[b]<?php
session_start();
..............................etc[/b]

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:[b]9[/b]) in C:\Documents and Settings\Work Station\Desktop\wamp\www\WebSite\forms\form1.php on line [b]61[/b]

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

so ! what is the problem !![/color]
Link to comment
Share on other sites

[color=brown]
Oh I really appreciate your help.. thanks alot..

now.. what about the [u]variables[/u] !! ?

[b]can I do this:[/b]

form.php[/color]
[code]
...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;
?>
[/code]
Link to comment
Share on other sites

[color=brown]
Okay  :)

I wrote in my form.php
[/color]
[code]

............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

[/code]

[color=brown]now ! .. in my query.php

should I do this:
[/color]
[code]
<?php
............etc

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

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

............etc
?>
[/code]
Link to comment
Share on other sites


[color=brown][b]I figured out that I should write these[/b][/color]

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

[color=brown][b]in my query.php  not  my form.php[/b][/color]


I wrote them in this way:

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

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

[/code]
Link to comment
Share on other sites

[color=brown]
but still ! .. should I write these lines of code in my query.php ??

[/color]
[code]
<?php
............etc

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

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

............etc
?>
[/code]
Link to comment
Share on other sites

[color=brown]
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 ?

[/color]
[code]
<?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;
}
?>
[/code]

[color=brown]
My question is mostly for this part ( sessions )
[/color]
[code]
<?php

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

?>
[/code]
Link to comment
Share on other sites

[quote author=web designer link=topic=102700.msg408968#msg408968 date=1154621544]
[color=brown]
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 !! [/color]
[/quote]

try reading the sessions in the FAQ: http://www.phpfreaks.com/forums/index.php/topic,31047.0.html
Link to comment
Share on other sites

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:

[b]form.php[/b]
[code=php:0]
<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>
[/code]

[b]query.php[/b]
[code=php:0]
<?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...
...
...
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.