Jump to content

Session Variables Suddenly Not Working


hobbiton73

Recommended Posts

I wonder whether someone may be able to help me please.

 

I'm using the form shown below to create a list of 'Locations' taken from a mySQL database. Then, via four form buttons, users can navigate to four separate screens all linked to back to the main Location record.

 

 

 <form name="mylocationsconsole" id="mylocationsconsole" method="post" action="locationsaction.php">
           							<?php
								include("admin/link.php");
								include("admin/opendb.php");
									$query = "SELECT * FROM `table` WHERE `userid` = '$idnum' ORDER BY locationname";
									$result = mysql_query($query) or die('error');
									$num = mysql_numrows($result);
									mysql_close($connect);					
									$i=0;
									while ($i < $num) {
									$lid=mysql_result($result,$i,"locationid");
									$lname=mysql_result($result,$i,"locationname");
									$laddress=mysql_result($result,$i,"returnedaddress");

								include("admin/link.php");
								include("admin/opendb.php");
									$fquery = "SELECT COUNT(*) num FROM table WHERE locationid = '$lid'";
									$fcount = mysql_query($fquery) or die('error');
									$row = mysql_fetch_assoc($fcount);
									$findscount = $row['num'];

								?>	
								<br />						
				  <table width="1325" border="0">
				  	<tr>
						<th width="17"></th>
						<th width="171"><div align="center">Location Name</div></th>
						<th width="278"><div align="left">Location Address</div></th>
						<th width="142"><div align="center">No. Of Finds Made </div></th>
						<th width="94"></th>
						<th width="76"></th>
						<th width="84"></th>	
						<th width="429"></th>								
					</tr>
					<tr>
						<td><input type="hidden" name="lid" value="<?=$lid?>" /></td>
						<td><div align="center"><?php echo $lname;?></div></td>
						<td><div align="left"><?php echo $laddress;?></div></td>
						<td><div align="center"><?php echo $findscount?></div></td>
						<td><div align="center"><input name="type" type="submit" value="View Details"/></div></td>
						<td><div align="center"><input name="type" type="submit" value="Add Finds"/></div></td>
						<td><div align="center"><input name="type" type="submit" value="Add Images"/></div></td>
						<td><div align="left"><input name="type" type="submit" value="View Location Finds"/></div></td>
					</tr>
					<tr>
						<th colspan="8"><br/><hr width="100%"></th></tr>
	  		      </table>
								<?php
									$i++;
									}
									if ($num == 0) {
								echo"<tr>
									  <td> </td>
									  <td> </td>
									  <td> </td>
									</tr>
									<tr>
									  <td> </td>
									  <td colspan='3'><div align='center'><strong>No locations have been added yet. <a href='saveaddress.php'>Click here</a> to add one.</strong></div></td>
									  <td> </td>
									</tr>
									<tr>
									  <td> </td>
									  <td> </td>
									  <td> </td>
									</tr>";
									}
								?>
		      </form>

 

This code below is the script called by the above form when one of the four form buttons is selected.

 

locationsaction.php

 

<?php 
session_start();
$_SESSION['lid'] = $_POST['lid'];
if (isset($_POST['type'])) {
    $urls = array(
        'View Details' => 'viewlocation.php',
        'Add Finds' => 'addfinds.php',
        'Add Images' => 'addimages.php',
	'View Location Finds' => 'locationfinds.php'
    );
    $url = $urls[$_POST['type']];
    header("Location: " . $url);
}
?>

 

All of the four receiving pages then have this

$lid = $_SESSION['lid'];
at the top of each page to capture the variable.

 

All of this was working fine up until two days ago, but the problem I now have is, irrespective of the number of locations in the list, the buttons take me to the correct screens but it is always for the last `Location` record in the list. I've rebuilt the pages which I think could be the problem but I still can't get this to work.

 

I just wondered whether someone may be able to look at this please and let me know where I'm going wrong, or perhaps suggest a better way of doing this.

 

Many thanks and kind regards

Link to comment
https://forums.phpfreaks.com/topic/264880-session-variables-suddenly-not-working/
Share on other sites

Hi @scootash, I just wanted to let you know that I've been able to solve this.

 

The problem was how I had set my form up to work with the data that was being through in my PHP script.

 

Although I need to sort out the formatting, this is my solution.

 

           

  <table width="732" border="0">
				  	<tr>
						<th width="17"></th>
					  <th width="62"><div align="center">Location Name</div></th>
						<th width="120"><div align="left">Location Address</div></th>
						<th width="81"><div align="center">No. Of Finds Made </div></th>
						<th width="86"></th>
						<th width="72"></th>
						<th width="84"></th>	
						<th width="769"></th>								
					</tr>
                <?php
					include("admin/link.php");
					include("admin/opendb.php");

					$query = "SELECT * FROM `table` WHERE `userid` = '$idnum' ORDER BY locationname";
					$result = mysql_query($query) or die('error');
					$num = mysql_num_rows($result);
					mysql_close($connect);

					$i=0;
					while ($i < $num) {
						$lid=mysql_result($result,$i,"locationid");
						$lname=mysql_result($result,$i,"locationname");
						$laddress=mysql_result($result,$i,"returnedaddress");

						include("admin/link.php");
						include("admin/opendb.php");
						$fquery = "SELECT COUNT(*) num FROM table WHERE locationid = '$lid'";
						$fcount = mysql_query($fquery) or die('error');
						$row = mysql_fetch_assoc($fcount);
						$findscount = $row['num'];
						mysql_close($connect);	
						?>
						<form name="mylocationsconsole" id="mylocationsconsole" method="post" action="locationsaction.php"/>
        		<tr>
						<td><input type="hidden" name="lid" value="<?=$lid?>" /></td>
						<td><div align="center"><?php echo $lname;?></div></td>
						<td><div align="left"><?php echo $laddress;?></div></td>
						<td><div align="center"><?php echo $findscount?></div></td>
						<td><div align="center"><input name="type" type="submit" value="View Details"/></div></td>
						<td><div align="center"><input name="type" type="submit" value="Add Finds"/></div></td>
						<td><div align="center"><input name="type" type="submit" value="Add Images"/></div></td>
						<td><div align="left"><input name="type" type="submit" value="View Location Finds"/></div></td>
				</tr>
					<tr>
						<th colspan="8"><br/><hr width="100%"></th></tr>
  		      </table>
		  </form>
								<?php
						$i++;
					}
					if ($num == 0) {
						echo"<tr>
                        		  <td> </td>
                        		  <td> </td>
                        		  <td> </td>
							  <td> </td>
                        		  <td> </td>
                        		</tr>
                        		<tr>
							  <td> </td>
                        		  <td colspan='3'><div align='center'><strong>No locations have been added yet. <a href='saveaddress.php'>Click here</a> to add one.</strong></div></td>
							  <td> </td>
                        		</tr>
                        		<tr>
                        		  <td> </td>
                        		  <td> </td>
                        		  <td> </td>
							  <td> </td>
                        		  <td> </td>
                        		</tr>";
					}
					?>
              </table>

 

Thank you very much for all your time and trouble.

 

All the best and kind regards

 

Archived

This topic is now archived and is closed to further replies.

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