session variable passing problem... please help!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robin1
Forum Newbie
Posts: 20
Joined: Thu Aug 01, 2002 4:36 pm

session variable passing problem... please help!!!

Post by robin1 »

What I’m trying to get my code to do.
From page1.php! send a record number to page2.php ( rec_num) by click on one of the records displayed.
Page2.php starts up by displaying that record (rec_num). The user clicks the button “assigning incident to myself”. At this point it uses the record number (rec_num)sent from page1.php to modify the record(searches the db using the rec_num to modify the record). Then the same record is re-display, reflecting the change. Everything works if it isn’t within a session but if it’s within a session the record number isn’t visible to the button(s).
To view what I have a test db is setup:
http://www.comgen.ca/helpdesk/helpdesk.php
id: testing4
pwd: testpwd4 --> click "HD queue menu" -->select a record by clicking on the number to the left which displays the details of the record.
Select “assigning incident to myself” . this step should run other code and redisplay the same record but its failing at this point.
i copy/pasted some parts of the code for view and the only button that works right now to make things simple is "assign incident to myself button".

Need ideas to fix this issue.. been working on it for a week and getting nowhere..
Thanks everybody.

page1.php

Code: Select all

$change_color = 1;
		while ($data=mysql_fetch_row($display_list))
		{	list($rec_id, $rec_quickline, $rec_category, $rec_city)=$data;
			if ($change_color == 1)
			{	echo "
				<tr class='myrow' bgcolor='#EEEEEE'>
				<td width='11%' height='23'> <font size='5'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_id."</a> </span> </font></td>
				<td width='47%' height='23'> <font size='4'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_quickline."</a> </span> </font></td>
				<td width='31%' height='23'> <font size='4'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_category."</a> </span> </font></td>
				<td width='11%' height='23'> <font size='4'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_city."</a> </span> </font></td>
				 </tr>";
				$change_color=0;
			&#125;
			else
			&#123;	//	$cit = (empty( $rec_city)) ? 'N/A' : " $rec_city";
				echo "
				<tr class='myrow' bgcolor='#FFFFFF'>
				<td width='11%' height='25'> <font size='5'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_id."</a> </span> </font></td>
				<td width='47%' height='25'> <font size='4'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_quickline."</a> </span> </font></td>
				<td width='31%' height='25'> <font size='4'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_category."</a> </span> </font></td>
				<td width='11%' height='25'> <font size='4'> <span class='class1'> <a href='myquedetail.php?rec_num=".$rec_id."'>".$rec_city."</a> </span> </font></td>
				 </tr>";
				$change_color = 1;
			&#125; //end of else statment
		&#125;//end of while statment
		echo "</table>";
page2.php

Code: Select all

<?php
session_start();
//echo $id_search;

//header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
//header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
//header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
//header("Pragma: no-cache"); // HTTP/1.0
//header("Cache-control: private"); 
if (!session_is_registered("useridfield")) 
&#123;
//if session isn't registered this html message is displayed...
echo '<html> 
 <head> 
 <title> Access Denied </title> 
 </head> 
 <body> 
 <h1> Access Denied </h1> 
 <p>Your user ID or password is incorrect, or you are not a 
    registered user on this site. To try logging in again, click 
    <a href="pwdpage.php">here</a>. To register for instant 
    access, click <a href="create_acc.php">here</a>.</p> 
 </body> 
 </html>';
exit(); 
&#125; 
else
&#123;
$record_number = $_GET&#1111;'rec_num'];
// database info
//session_register("cmd");

/*********************************************************************************/
if (!isset($_POST&#1111;'Action'])) $_POST&#1111;'Action'] = '';
if (!isset($_SESSION&#1111;'FormProcessed'])) $_SESSION&#1111;'FormProcessed'] = 0;
//***********send and take button controls*************************************
$localtime_date = date(" F d, Y g:i a",time() + (3 * 60 * 60));
$time_date_sent = "<BR> <HR>Incident/Request forwarded to HD at $localtime_date by consultent: $useridfield .";
$time_date_taken = "<BR> <HR>Incident/Request taken at $localtime_date by consultent: $useridfield";
//****************testing to blank in dbprob_owner **************************
mysql_connect($host, $user, $pwd);
@mysql_select_db($database) or die("Not able to connect to database");
$query2 = "select dbprob_fix from dbt_customer where dbcust_id = '$record_number'";
$results2 = mysql_query($query2) or die(mysql_error());
$row2 = mysql_fetch_array($results2);
mysql_close();
//****************testing  blank in dbprob_owner **************************
// code to assigne call to yourself
/****************************************************/
/****************************************************/
/********problem area is with the button function********/
/********record number isn't received at this point**************/
/****************************************************/

if(isset($take_button))
&#123;    mysql_connect($host, $user, $pwd);
	@mysql_select_db($database) or die("Not able to connect to database");
	$query1 ="update dbt_customer set dbprob_owner = '$useridfield' where dbcust_id = '$record_number'";
	mysql_query($query1) or die(mysql_error());
	mysql_close();	
	if (empty($row2&#1111;'dbprob_fix']))
		&#123;   	mysql_connect($name, $user, $pwd);
			@mysql_select_db($database) or die("Not able to connect to database");
			$querytime_date ="update dbt_customer1 set dbprob_fix = '$time_date_taken' where dbcust_id = '$record_number'";
			mysql_query($querytime_date) or die(mysql_error());
			mysql_close();
			header("Location: http://www.comgen.ca/helpdesk/myquedetail.php");
			exit();
		&#125;
		else
		&#123;	mysql_connect($host, $user, $pwd);
			@mysql_select_db($database) or die("Not able to connect to database");
			$query1 = "update dbt_customer set dbprob_fix = concat(dbprob_fix, '$time_date_taken') where dbcust_id = '$record_number'";
			mysql_query($query1) or die(mysql_error());
			mysql_close();
			$_SESSION&#1111;'FormProcessed'] = 1;
			header("Location: http://www.comgen.ca/helpdesk/myquedetail.php");
			exit();
		&#125; 
&#125; //end of takent button

//*** code for the return button to send the call back to the helpdesk...
/*



/**************************************************************
//&#123;// db opened and abstracted info to display
mysql_connect($host, $user, $pwd);
@mysql_select_db($database) or die("Not able to connect to database");
$query1 = "select dbcust_id, dbcust_fname, dbcust_lname, dbcust_street, dbcust_city, dbcust_prov_sta, dbpostal, dbcust_email, dbcust_phonenumber, dbprob_description, dbprob_category, dbprob_or_sys, dbprob_err_msg, dbprob_pc_info, dbprob_userfix, dbprob_date, dbprob_fix, dbprob_owner from dbt_customer where dbcust_id = '$record_number'";
$results1 = mysql_query($query1) or die(mysql_error());
$row = mysql_fetch_array($results1);
mysql_close();
$incidentnum_web = $row&#1111;'dbcust_id'];
$username_web = $row&#1111;'dbcust_fname'] ." ".$lname_web = $row&#1111;'dbcust_lname'];
$street_web = $row&#1111;'dbcust_street'];
$city_web = $row&#1111;'dbcust_city'];
$province_web = $row&#1111;'dbcust_prov_sta'];
$postal_web = $row&#1111;'dbpostal'];
$email_web = $row&#1111;'dbcust_email'];
$phone_web = $row&#1111;'dbcust_phonenumber'];
$description_web = $row&#1111;'dbprob_description'];
$category_web = $$row&#1111;'dbprob_category'];
$opsys_web = $row&#1111;'dbprob_or_sys'];
$errmsg_web = $row&#1111;'dbprob_err_msg'];
$pcinfo_web = $row&#1111;'dbprob_pc_info'];
$userfix_web = $row&#1111;'dbprob_userfix'];
$probdate_web = $row&#1111;'dbprob_date'];
$probfix_web = $row&#1111;'dbprob_fix'];
$dbprobowner_web = $row&#1111;'dbprob_owner'];
// ************************* wheather to disable button controls *************************/
// if statment that controls which button to disable.. if the call is taken the assigned to myself
// button is disabled and if not the send button is disabled
IF(!empty($dbprobowner_web))
	&#123; $send_button = 'disabled';	   
	&#125;
	else
	&#123; $take_button = 'disabled'; 
	$disable_close_call = 'disabled';&#125;
//********************************************************************************************/
echo"<html>";
echo"<head>";
echo"<title>Incident/Report detail sheet</title>";
echo"</head>";
echo"<body onload='javascript:window.refresh();'>";
echo"<div align='center'>";

  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td width='183'>$record_number</td>";
      echo"<td width='364'><div align='center'><font color='#000000' size='6'>Incident/Report ",
          "detail sheet </font></div></td>";
      echo"<td width='239'><div align='right'>$useridfield</div></td>";
    echo"</tr>";
  echo"</table>";
  echo"<hr>";
   echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
  echo '<table width="800" border="1" align="center" cellpadding="5" cellspacing="0">
    <tr bordercolor="#6699CC" bgcolor="#6699CC"> 
      <td width="87"><strong><font color="#FFFFFF"><a href="management1.php"><font color="#FFFFFF">Main 
        menu</font></a></strong></td>
      <td width="79"><div align="center"><strong><a href="myqueue.php" target="_self"><font color="#FFFFFF">My 
          Queue</font></a></strong></div></td>
      <td width="80"><div align="center"><strong><a href="hdqueue.php" target="_self"><font color="#FFFFFF">HD 
          Queue</font></a></strong></div></td>
      <td width="55"><div align="center"><strong><a href="www.comgen.ca" target="_self"><font color="#FFFFFF">Email</font></a></strong></div></td>
      <td width="77"><div align="center"><strong><a href="www.comgen.ca" target="_self"><font color="#FFFFFF">My 
          Profile</font></a></strong></div></td>
      <td width="135"><div align="center"><strong><a href="www.comgen.ca" target="_self"><font color="#FFFFFF">Password 
          change</font></a></strong></div></td>
      <td width="46"><div align="center"><strong><a href="www.comgen.ca"><font color="#FFFFFF">FAQs</font></a></strong></div></td>
      <td width="70"><div align="center"><strong><a href="www.comgen.ca" target="_self"><font color="#FFFFFF">HD 
          Stats</font></a></strong></div></td>
      <td width="61"><div align="center"><strong><a href="www.comgen.ca"><font color="#FFFFFF">Logout</font></a></strong></div></td>
    </tr>
  </table> ';
  
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
  echo "<table width='800' border='1' align='center' cellpadding='5' cellspacing='0'>";
    echo "<tr>";
      echo "<td width='800' bgcolor='#00CCCC'><strong>Information Centre</strong></td>";
    echo "</tr>";
    echo "<tr>";
      echo "<td height='123'><table width='791' align='center'>";
          echo "<tr>";
            echo "<td width='106'><div align='right'><font size='2'><strong>Client Name:</strong></font></div></td>";
            echo "<td width='270'><font size='2'>$username_web</font></td>";//first and last name field
            echo "<td width='139'><div align='right'><strong><font size='2'>Incident/Report ",
                "number:</font></strong></div></td>";
            echo "<td width='256'><font size='2'>$incidentnum_web</font></td>"; //call number
          echo "</tr>";
          echo "<tr>";
            echo "<td><div align='right'><font size='2'><strong>City:</strong></font></div></td>";
            echo "<td><font size='2'>$city_web</font></td>"; //city
            echo "<td><div align='right'><strong><font size='2'><strong>Date posted:</strong></font></strong></div></td>";
            echo "<td><font size='2'>$probdate_web</font></td>"; //date
          echo "</tr>";
          echo "<tr>";
            echo "<td><div align='right'><font size='2'><strong>Street:</strong></font></div></td>";
            echo "<td>$street_web</td>"; //street
            echo "<td><div align='right'><strong><font size='2'>Category:</font></strong></div></td>";
            echo "<td>$category_web</td>"; //category
          echo "</tr>";
          echo "<tr>";
            echo "<td height='21'><div align='right'><font size='2'><strong>Province:</strong></font></div></td>";
            echo "<td><font size='2'>$province_web</font></td>"; //province
            echo "<td><div align='right'><strong><font size='2'><strong>Operating system:</strong></font></strong></div></td>";
            echo "<td>$opsys_web</td>"; //operating system
          echo "</tr>";
          echo "<tr>";
            echo "<td height='29'><div align='right'><font size='2'><strong><font size='2'><strong><font size='2'>Contact ",
                "number</font></strong>:</font></strong></font></div></td>";
            echo "<td><font size='2'>&nbsp;$phone_web</font></td>"; //phone number
            echo "<td><div align='right'><strong><font size='2'><strong><font size='2'>Email ",
                "address</font></strong></font></strong></div></td>";
            echo "<td>$email_web</td>"; //email
          echo "</tr>";
        echo "</table>";
      echo "</td>";
    echo "</tr>";
 echo " </table>";
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' height='87' border='1' cellpadding='5' cellspacing='0'>";
    echo"<tr>";
      echo"<td height='23' bgcolor='#00CCCC'><strong>Incident/Request detail description</strong></td>";
    echo"</tr>";
    echo"<tr>";
      echo"<td>$description_web</td>"; // problem description
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' height='87' border='1' cellpadding='5' cellspacing='0'>";
    echo"<tr> ";
      echo"<td height='23' bgcolor='#00CCCC'><strong>Error message</strong></td>";
    echo"</tr>";
    echo"<tr>";
      echo"<td>$errmsg_web</td>"; //error message
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' height='87' border='1' cellpadding='5' cellspacing='0'>";
    echo"<tr>";
      echo"<td height='23' bgcolor='#00CCCC'><strong>Description of PC</strong></td>";
    echo"</tr>";
    echo"<tr>";
      echo"<td>$pcinfo_web</td>"; //description of pc
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' height='87' border='1' cellpadding='5' cellspacing='0'>";
    echo"<tr>";
      echo"<td height='23' bgcolor='#00CCCC'><strong>What the client did to fix the problem</strong></td>";
    echo"</tr>";
    echo"<tr>";
      echo"<td>$userfix_web</td>"; //what the client did to fix the problme
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' height='87' border='1' cellpadding='5' cellspacing='0'>";
    echo"<tr>";
      echo"<td height='23' bgcolor='#00CCCC'><strong>Suggestions and ideas for problem fix</strong></td>";
    echo"</tr>";
    echo"<tr>";
      echo"<td>$probfix_web</td>"; //possible fix
    echo"</tr>";
  echo"</table>";
  echo '<FORM NAME="ContactForm" ACTION="' . $_SERVER&#1111;'PHP_SELF'] . '" METHOD="POST">'; //form tag
  echo"<table width='800' border='0' align='center' cellpadding='5' cellspacing='0'>";
    echo"<tr>";
      //echo"<td>&nbsp;</td>";
	 echo "<td><INPUT TYPE=HIDDEN NAME='Action' VALUE='Register'></td>";
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' height='151' border='1' cellpadding='5' cellspacing='0'>";
      echo"<tr>";
	      echo"<td height='23' bgcolor='#00CCCC'><strong>Add to the  suggestions and ideas ",
        "for problem fix</strong></td>";
    echo"</tr>";
    echo"<tr>";
      echo"<td height='120'>";
          echo"<textarea name='actionline' cols='96' rows='10'></textarea>";
        echo"</td>";
    echo"</tr>";
  echo"</table>";
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
//*********************** Button controls********************************************/
 echo "<table width='800' height='32' align='center'>";
    echo "<tr>";
      echo "<td width='214'> <div align='center'>", //assigne incident to myself button
           "<input name='take_button' type='submit' value='Assign Incident to myself' $send_button>",
           "</div></td>";
      echo "<td width='221'><div align='center'>", // return to hd button
           "<input name='return_button' type='submit' value='Return Incident to HD queue' $take_button>",
           "</div></td>";
      echo "<td width='175'> <div align='center'>", //form clear button
           "<input name='resetform1' type='reset' value='Clear entery'>",
           "</div></td>"; //append button
      echo "<td width='170' height='26'> <div align='right'>",
		 "<input name='addactionline' type='submit' value='Append to suggestion'>",
           "</div></td>";
	echo "</tr>";
  echo "</table>"; 
  echo "<table width='800' border='0' align='center'>";
	echo "<tr>";
		echo "<td width='211'> <input name='closecallbutton' type='submit' value='Close Incident/Request  ' $disable_close_call> </td>";
			 echo "<td width='579'><font color='#FF0000'>Once the Incident/Request is completed, ",
			"update and close call.</font></td>";
     echo "</tr>";
  echo "</table>";
//*******************************************************************************************/
  echo "</form>"; //end of button control / table
  echo"<hr align='center'>";
  echo"<table width='800' border='0' align='center'>";
    echo"<tr>";
      echo"<td>&nbsp;</td>";
      echo"<td><div align='center'><font size='2'>www.comgen.ca</font></div></td>";
      echo"<td>&nbsp;</td>";
    echo"</tr>";
  echo"</table>";
echo"</div>";
echo"</body>";
echo"</html>";
$_SESSION&#1111;'FormProcessed'] = 0;
&#125;
//&#125;

?>
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

I haven't looked over everything, but one thing that does stand out to me is your use of if

Code: Select all

if (isset($take_button))
I'm assuming that $take_button comes from the form... In which case it should be $_GET["take_button"] or $_POST["take_button"]

PS. Please use [ php ] in the future not [ code ]
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

OK, and here's why rec_num isn't getting passed along correctly:

You pull $record_number into the local scope by using $_GET["rec_num"] near the top of page2.php. However when you redirect off of page2.php in the take_button code, you don't pass rec_num as a GET parameter again, ie

Code: Select all

header("Location: http://www.comgen.ca/helpdesk/mydetail. ... ord_number");
Or alternatively you could pass it as session variable, etc. However it must be passed somehow.....
robin1
Forum Newbie
Posts: 20
Joined: Thu Aug 01, 2002 4:36 pm

Post by robin1 »

Hi,
thanks for getting back to me on this problem..
problem still remains.. it's still not seeing the record number within the take button....

Code: Select all

if(isset($take_button))
{    mysql_connect($host_name, $database_user, $database_pwd);
	@mysql_select_db($database_name) or die("Not able to connect to database");
	$query1 ="update dbt_customer1 set dbprob_owner = '$useridfield' where dbcust_id = '$record_number'";
	mysql_query($query1) or die(mysql_error());
	mysql_close();	
	if (empty($row2['dbprob_fix']))
		{   	mysql_connect($host_name, $database_user, $database_pwd);
			@mysql_select_db($database_name) or die("Not able to connect to database");
			$querytime_date ="update dbt_customer1 set dbprob_fix = '$time_date_taken' where dbcust_id = '$record_number'";
			mysql_query($querytime_date) or die(mysql_error());
			mysql_close();
						header("Location: http://www.comgen.ca/helpdesk/myquedeta ... ord_number"); 
			exit();
		}
		else
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Oops, yes I was a littly hasty in my response. That addition of the ?rec_num=$record_number would work if rec_num were getting to that page, but its not.

rec_num is not getting passed when you press the button because the button POSTs a form. You need to either
1. Add a hidden form element named rec_num to your form AND
a) change the form to using GET (and the assoicated $_POSTs to $_GETS) OR
b) leave the form as POST, but check $_POST["rec_num"] as well as $_GET
OR
2. Stick rec_num in a session variable once selected and always pull it out of the session.

It seems to be that you're currently a little confused about how variables get passed between pages. You might want to read up on GET/POST/SESSION and make sure you know where all your variables are coming from.

Just because a page submit's back to itself, does not mean that all the variables it had before are still there. Unless they are passed (via GET/POST/COOKIE/SESSION) they are gone.
Post Reply