hey i want to use session id from index page to other page...bt when i use it by post method and click on the id text thn it will show the data and thn the id is being destroyed...how to keep the same id tehre...plz help me...

make sure to share the relevant code and you have to start the session on each page with session_start() if session_autostart directive in php.ini is not enabled..

Index page:

<?php
session_start();
echo '<p>Your session id is: ' . session_id() . '</p>';

Other page:

<?php
session_start();
echo '<p>Your session id is: ' . session_id() . '</p>';

See if they match if you will ;).

if i want to use index page id in 2nd page and then in 2nd page i want to use that id  again as...
for index page:


 <?php $q="SELECT * FROM inner_pages WHERE sub_title='6' ORDER BY inner_id DESC limit 0,10";
        $output=mysql_query($q) or die (mysql_error().$q);
          while ($rows=mysql_fetch_array($output)){
          ?>                        
                        <tr>
                            <td align="left"  class="sidebar" style="padding-left:5px;"><a href="abc.php?sub1_id=<?php echo $rows['id']; ?>"><?php echo $rows['inner_title'];?></a></td>
                          </tr>
                          <tr>
                            <td align="left"><img src="images/horiz_divder.jpg" width="180" height="1" /></td>
                          </tr>
                          <?php } ?>

nd 2nd page code is like:

<tr>
            <?php 
                $sub_id= $_GET['sub_id'];
                $q="SELECT * FROM post WHERE category ='$sub_id'";
                $output=mysql_query($q) or die (mysql_error().$q);
                while ($rows=mysql_fetch_array($output)){
            ?>                        
                        <tr>
                            <td align="left"  class="sidebar" style="padding-left:5px;"><span class="sidebar" style="padding-left:5px;"><a href="abc.php?p_id=<?php echo $rows['id']; ?>"><?php echo $rows['title'];?></a></span></td>
                          </tr>
                          <tr>
                            <td align="left"><img src="images/horiz_divder.jpg" width="220" height="1" /></td>
                          </tr>
                          <?php } ?>
</tr>

now i have other code in 2nd page:

  <?php 
                   $p_id= $_GET['p_id']; 
                  $q="SELECT * FROM post WHERE id='$p_id' ORDER BY id ";
        $output=mysql_query($q) or die (mysql_error().$q);
          $rows=mysql_fetch_array($output);
          ?> 
 <tr>
                    <td height="35" align="left"><h2 style="color:#2C66A1; text-transform:capitalize;"><?php echo $rows['title'];?></h2></td>
                  </tr> 
                  <tr>
                    <td class="text"> </td>
                  </tr>
                  <tr>
                    <td class="text"><?php echo $rows['description'];?></td>
                  </tr>
                  <tr>
                    <td class="text"> </td>
                  </tr> 



now when i use 2nd page sub_id will not recirved 2nd time...means the data in table which get sub_id is not shown....


dnt knw how to explain...bt anyone understnd plz help me to get out of it...
thnks...

Ok so let's clear this up a little bit. You have a page called index.php. It retrieves data from your database. Now which ID do you want to use on page 2, and how do you get to page 2? Do you get there by submitting a form, clicking a link, something like that?

Using the session to save a variable goes as follows, in case you need to use it:

  1. At the start of your page, place the session_start(); command.

  2. You can now save anything on your page in $_SESSION['your_key_name'], e.g. $_SESSION['user_id'] = $user_id;.

  3. You can now also access session information on your page. Let's say that on a previous page you have saved something in $_SESSION['page_id']. You can now access that variable by simply using $_SESSION['page_id'];, e.g. echo $_SESSION['page_id'];.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.