473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

session help - copying mysql variables from page 1 to page 2

201 100+
hello -

my sessions are working fine; how ever i've added some more variables to them.

problem:
page one: i have the variables, from the mysql result set. i.e. message, to reply set those variables in sessions from the current page to be copied over to the next page.

second page: it pulls the variables in no problem, but the query on insert is erroring out. saying that its should not be a result it should be a resource.

page one code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (!isset($_SESSION)) {
  3.   session_start();
  4. }
  5. ?>
  6. <?php require_once('mail.php'); ?>
  7. <?php
  8. if (!function_exists("GetSQLValueString")) {
  9. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  10. {
  11.   if (PHP_VERSION < 6) {
  12.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  13.   }
  14.  
  15.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  16.  
  17.   switch ($theType) {
  18.     case "text":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;    
  21.     case "long":
  22.     case "int":
  23.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  24.       break;
  25.     case "double":
  26.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  27.       break;
  28.     case "date":
  29.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  30.       break;
  31.     case "defined":
  32.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  33.       break;
  34.   }
  35.   return $theValue;
  36. }
  37. }
  38.  
  39. $currentPage = $_SERVER["PHP_SELF"];
  40.  
  41. $Id = $_SESSION['Id'];   
  42. $Name = $_SESSION['name']; 
  43. $Group = $_SESSION['Group'];
  44.  
  45. if (isset($_GET['MailId'])) {
  46.  
  47.     $Mail_Id = htmlspecialchars($_GET['MailId']) ;
  48.  
  49. }
  50.  
  51. $Mail_vId = $Mail_Id ; 
  52.  
  53. $maxRows_MailView = 1;
  54. $pageNum_MailView = 0;
  55. if (isset($_GET['pageNum_MailView'])) {
  56.   $pageNum_MailView = $_GET['pageNum_MailView'];
  57. }
  58. $startRow_MailView = $pageNum_MailView * $maxRows_MailView;
  59.  
  60. mysql_select_db($database_Mail, $Mail);
  61. $query_MailView = "SELECT FromUser  as Name, Subject , Date, Id, Mail FROM mail where id='$id''";
  62. $query_limit_MailView = sprintf("%s LIMIT %d, %d", $query_MailView, $startRow_MailView, $maxRows_MailView);
  63. $MailView = mysql_query($query_limit_MailView, $Mail) or die(mysql_error());
  64. $row_MailView = mysql_fetch_assoc($MailView);
  65.  
  66. $FromUser = mysql_result($MailView,0,'FromUser') ;
  67. $Subject = mysql_result($MailView,0,'Subject') ; 
  68. $Mail = mysql_result($MailView,0,'Mail') ;
  69. $Id = mysql_result($MailView,0,'Id') ; 
  70.  
  71. $_SESSION['ToUser'] = $FromUser ; 
  72. $_SESSION['Subject'] = $Subject ; 
  73. $_SESSION['Mail'] = $Mail ; 
  74. $_SESSION['Id'] = $Id ; 
  75.  
  76.  
  77. if (isset($_GET['totalRows_MailView'])) {
  78.   $totalRows_MailView = $_GET['totalRows_MailView'];
  79. } else {
  80.   $all_MailView = mysql_query($query_MailView);
  81.   $totalRows_MailView = mysql_num_rows($all_MailView);
  82. }
  83. $totalPages_MailView = ceil($totalRows_MailView/$maxRows_MailView)-1;
  84.  
  85. $queryString_MailView = "";
  86. if (!empty($_SERVER['QUERY_STRING'])) {
  87.   $params = explode("&", $_SERVER['QUERY_STRING']);
  88.   $newParams = array();
  89.   foreach ($params as $param) {
  90.     if (stristr($param, "pageNum_MailView") == false && 
  91.         stristr($param, "totalRows_MailView") == false) {
  92.       array_push($newParams, $param);
  93.     }
  94.   }
  95.   if (count($newParams) != 0) {
  96.     $queryString_MailView = "&" . htmlentities(implode("&", $newParams));
  97.   }
  98. }
  99. $queryString_MailView = sprintf("&totalRows_MailView=%d%s", $totalRows_MailView, $queryString_MailView);
  100.  
  101. ?>
  102. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  103. <html xmlns="http://www.w3.org/1999/xhtml">
  104. <head>
  105. <title>  Mail View</title>
  106. <div id="container">
  107.  <div id="header">
  108.     <h1>&nbsp;</h1>
  109.     <p>&nbsp;</p>
  110.     <p>&nbsp;</p>
  111.   <!-- end #header --></div>
  112.   <div id="sidebar1">
  113.   <h3>&nbsp;    </h3>
  114.     <!-- end #sidebar1 --></div>
  115.   <div id="sidebar2">
  116.     <h3>&nbsp;</h3>
  117.   <!-- end #sidebar2 --></div>
  118.   <div id="mainContent">
  119.     <h1>&nbsp;</h1>
  120.     <form name="form1" method="post" action="">
  121.     <table border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC" width="100%" height="100%">
  122.       <tr></tr>
  123.       <caption align="center" valign="top">
  124.         Mail View
  125.       </caption>
  126.       <?php do { ?>
  127.       <tr>
  128.         <td>From User: <?php echo $row_MailView['name']; ?></td>
  129.       </tr>
  130.       <tr>
  131.         <td>Subject: &nbsp;<?php echo $row_MailView['title']; ?></td>
  132.       </tr>
  133.       <tr>
  134.         <td>Date: &nbsp;<?php echo $row_MailView['Date']; ?></td>
  135.       </tr>
  136.       <tr>
  137.         <td>Message: <br /> &nbsp; &nbsp; &nbsp;<?php echo $row_MailView['Mail']; ?></td>
  138.       </tr>
  139.      <?php } while ($row_MailView = mysql_fetch_assoc($MailView)); ?>
  140.     </table>
  141.     <table align="center">
  142.      <tr>
  143.       <td><a href="mail_reply.php"><input type="submit"  name="reply" value="Reply" id="reply" /></a></td>
  144.       </tr>
  145.     </table>
  146. </form>
  147. <h2>&nbsp;</h2>
  148. </body>
  149. </html>
  150. <?php
  151. mysql_free_result($mail);
  152. ?>
  153.  
  154.  
page two code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (!isset($_SESSION)) {
  3.   session_start();
  4. }
  5. ?>
  6. <?php require_once('Mail.php'); ?>
  7. <?php require_once('Friends.php'); ?>
  8. <?php
  9. if (!function_exists("GetSQLValueString")) {
  10. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  11. {
  12.   if (PHP_VERSION < 6) {
  13.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  14.   }
  15.  
  16.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  17.  
  18.   switch ($theType) {
  19.     case "text":
  20.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  21.       break;    
  22.     case "long":
  23.     case "int":
  24.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  25.       break;
  26.     case "double":
  27.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  28.       break;
  29.     case "date":
  30.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  31.       break;
  32.     case "defined":
  33.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  34.       break;
  35.   }
  36.   return $theValue;
  37. }
  38. }
  39.  
  40. $Id = $_SESSION['Id']; 
  41. $Name = $_SESSION['name'];
  42. $Group = $_SESSION['Group']; 
  43.  
  44. $FromUser = $_SESSION['ToUser'] ; 
  45. $Subject = $_SESSION['MM_Subject'] ; 
  46. $Mail = $_SESSION['Mail'] ;
  47. $Id = $_SESSION['Id'] ; 
  48.  
  49.  
  50. $editFormAction = $_SERVER['PHP_SELF'];
  51. if (isset($_SERVER['QUERY_STRING'])) {
  52.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  53. }
  54.  
  55. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  56.  
  57.  
  58.   // insert into mail table
  59.   $insertSQL1 = sprintf("INSERT INTO mail (Id, SubjectId, ToUser, FromUser, `Date`) VALUES (null, last_insert_id(), '$ToUser', '$Id', now())")                                
  60.  
  61.  
  62.  
  63.   mysql_select_db($database_Mail, $Mail);
  64.   $Result = mysql_query($insertSQL1, $Mail) or die(mysql_error());
  65.  
  66.   $insertGoTo = "mail.php";
  67.   if (isset($_SERVER['QUERY_STRING'])) {
  68.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  69.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  70.   }
  71.   header(sprintf("Location: %s", $insertGoTo));
  72. }
  73.  
  74. mysql_select_db($database_Friends, $Friends);
  75. $query_Friends = "SELECT Name FROM Friends WHERE id='$FromUser' ";
  76. $Friends = mysql_query($query_Friends, $Friends) or die(mysql_error());
  77. $row_Friends = mysql_fetch_assoc($Friends);
  78. $totalRows_Friends = mysql_num_rows($Friends);
  79.  
  80. ?>
  81. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  82. <html xmlns="http://www.w3.org/1999/xhtml">
  83. <head>
  84. <title>Messages - New</title>
  85. <style type="text/css"> 
  86. </head>
  87.  
  88. <div id="container">
  89.  <div id="header">
  90.     <h1>&nbsp;</h1>
  91.     <p>&nbsp;</p>
  92.     <p>&nbsp;</p>
  93.   <!-- end #header --></div>
  94.   <div id="sidebar1">
  95.   <h3>&nbsp;    </h3>
  96.   <!-- end #sidebar1 --></div>
  97.   <div id="sidebar2">
  98.     <h3>&nbsp;</h3>
  99.   <!-- end #sidebar2 --></div>
  100.   <div id="mainContent">
  101.     <h1>&nbsp;</h1>
  102. <h2>&nbsp;</h2>
  103.   <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  104.     <table align="center" height="100" width="100">
  105.       <tr valign="baseline">
  106.         <td nowrap="nowrap" align="right">To:</td>
  107.         <td><select id="ToUser" name="ToUser">
  108.           <?php
  109. do {  
  110. ?>
  111.           <option value="<?php echo $row_Friends['Id']?>"<?php if (!(strcmp($row_Friends['Name'], $FromUser=$_SESSION['ToUser']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Friends['Name']?></option>
  112.           <?php
  113. } while ($row_Friends = mysql_fetch_assoc($Friends));
  114.   $rows = mysql_num_rows($Friends);
  115.   if($rows > 0) {
  116.       mysql_data_seek($Friends, 0);
  117.       $row_Friends = mysql_fetch_assoc($Friends);
  118.   }
  119. ?>
  120.         </select></td>
  121.         </tr>
  122.       <tr valign="baseline">
  123.         <td nowrap="nowrap" align="right">Subject:</td>
  124.         <td><input type="text" name="Subject" value="Re: <?php echo $Subject ; ?> " id="Subject" size="32" /></td>
  125.       </tr>
  126.       <tr valign="baseline">
  127.         <td nowrap="nowrap" align="center" valign="top">Mail:</td>
  128.         <td><textarea name="Mail" cols="80" rows="30" id="Mail">  <?php echo "\n\n\n\n\n***********************************************************************************************************\n\n"; echo $Mail ; ?> </textarea></td>
  129.       </tr>
  130.       <tr valign="baseline">
  131.         <td nowrap="nowrap" align="right">&nbsp;</td>
  132.         <td><input type="submit" value="Send" name="Send" /></td>
  133.       </tr>
  134.     </table>
  135.       <input type="hidden" name="MM_insert" value="form1" />
  136.     </form>
  137.   <p>&nbsp;</p>
  138.     <p>&nbsp;</p>
  139.   <!-- end #mainContent --></div>
  140. </html>
  141. <?php
  142. mysql_free_result($Friends);
  143. ?>
  144.  
  145.  
thanks, in advance for your help,

theo werntz ii
Jan 29 '10 #1
0 1445

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chip | last post by:
I am trying to get sessions to work on a log in screen to give certain users access to certain pages/directories. The problem is that when the login button is pushed (or the enter key pressed) the...
3
by: Michael J. Astrauskas | last post by:
I have a site where a user logs in and a session variable I created is used to keep track of the fact that the user is logged in. This various pages query a MySQL database to get information...
0
by: james | last post by:
I am new to php and need some help getting the session variables into include files. (after-thought, Sorry for the drawn out post but I really, really need help....;) Here's what I'm doing.. ...
6
by: bonehead | last post by:
I'm still a novice when it comes to session security issues. The problems I'm trying to solve may be fairly common, but I haven't seen examples of solutions in any of the books I've looked at. I...
3
by: Bob Bedford | last post by:
I'm planning to modify my site from "POST" to "SESSION"....This is because many times, when clicking "back" on the browser, the page has to be refreshed, and I absolutely want to avoid this, also I...
1
by: Dave Smithz | last post by:
Hi there, I have implemented a login sequence using session variables for a PHP/MySQL DB which I took over development. I read some books and this NG and it seemed straight forward. However the...
5
by: Eugene Anthony | last post by:
In my login.asp I have the following code: <!--#include file="database_Function.asp"--> <% Dim sSessionID, sMessage If Len(Request.Form("cmdSubmit")) > 0 then mySQL = "EXECUTE...
4
by: Chris Newby | last post by:
My project currently requires that I integrate an ASP.NET application with an ASP application. One of the issues I'm having is that I have some very long strings being created in an ASP.NET...
7
by: Japhy | last post by:
Hello, I need to save values typed into forms across several scripts, before the user actually 'submits' the form to update the mysql db. I have been exploring ways to do this, and looking for...
2
by: Michaelk | last post by:
Can somebody tell me how many Session variables would be considered exessive, and when they start really affect the server speed. For example on 20-30 asp pages I need to use about 200-300 session...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.