session message printing problem

Reply

Join Date: Mar 2009
Posts: 23
Reputation: itsrahulk is an unknown quantity at this point 
Solved Threads: 0
itsrahulk itsrahulk is offline Offline
Newbie Poster

session message printing problem

 
0
  #1
Oct 27th, 2009
hi all,


i am not able to print the message which i taken in session variable
$_SESSION['msg'] ="* Property details saved successfully"

i am posting all the values on the same page and redirected the header to get all the updated values back.

but when i use unset($_SESSION['msg']) after echoing this session variable it does not appear, but when i removed the unset($_SESSION['msg']) message is being appear.

i am not getting what is the problem in the source code
complete page source code is below

Please help me

Thanks.


  1. <?php
  2. /* check sesison */
  3. require_once('chksession.php');
  4. require_once('includes/dbconfig.php');
  5. $rs1 = $db->fnSelect('tbl_hotel','*','id='.$_SESSION['pid']) or die('There is some technical problem');
  6. /* get all the details of property */
  7. ?>
  8. <?php
  9. /* update all the property details */
  10. if ($_POST['action']=='save') {
  11. /** check all the values those are required on the server side */
  12. require_once('includes/class/validation.class.php');
  13. $location = htmlspecialchars(strip_tags($_POST['location_name']));
  14. $beach = htmlspecialchars(strip_tags($_POST['beach']));
  15. $propertyname = htmlspecialchars(strip_tags($_POST['property_name']));
  16. $acc_type = htmlspecialchars(strip_tags($_POST['acc_type']));
  17. $address = htmlspecialchars(strip_tags($_POST['street_address']));
  18. $owner = htmlspecialchars(strip_tags($_POST['owner']));
  19. $website_url = htmlspecialchars(strip_tags($_POST['website_url']));
  20. $t = "NOW()";
  21.  
  22. /* initialize obj object for validation */
  23. $obj = new PhpServerValidation();
  24. $obj->fnGetFields($location,'req','Location name is required');
  25. $obj->fnGetFields($propertyname,'req','Property name is required');
  26. $obj->fnGetFields($acc_type,'req','Accomodation Type is required');
  27. $obj->fnGetFields($address,'req','Steet Address is required');
  28. $obj->fnGetFields($owner,'req','Authority is required');
  29.  
  30. /* validate all the fields */
  31. $error = $obj->fnFieldsvalidation();
  32.  
  33. /* if there is an error display it out */
  34. if (!empty($error)) {
  35. $error_msg = '<UL>'.$error.'</UL>';
  36. }
  37. /* update all the fields */
  38. else {
  39. $loc = array();
  40. $loc = explode("::",$location);
  41. /* check if checkboxes values are preset */
  42. if ($_POST['chk']) {
  43. /* make a string of all the features */
  44. $fe = implode(",",$_POST['chk']);
  45. } else {
  46. $fe = '';
  47. }
  48. $fields = "name='$propertyname',location_zone='$loc[0]',location_area='$loc[1]',address='$address',beach='$beach',property_type ='$acc_type',owner='$owner',features='$fe',date_time=$t";
  49. $condition = 'id='.$_SESSION['pid'];
  50. //update the values into table
  51. $outputupdate = $db->fnUpadte('tbl_hotel',$fields,$condition);
  52. if ($outputupdate) {
  53. $_SESSION['msg'] = "* property details saved successfully"
  54. header('Location:property_details.php?pid='.$_SESSION['pid'].) ;
  55. }
  56. }
  57. }
  58. ?>
  59. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  60. <html xmlns="http://www.w3.org/1999/xhtml">
  61. <head>
  62. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  63. <title>Goaseahomes Owner Admin - <?php echo $_SESSION['pname'] ?></title>
  64. <link rel="stylesheet" type="text/css" href="css/theme.css" />
  65. <link rel="stylesheet" type="text/css" href="css/style.css" />
  66. <!--[if IE]>
  67. <link rel="stylesheet" type="text/css" href="css/ie-sucks.css" />
  68. <![endif]-->
  69. <script>
  70. function chk() {
  71. var form = document.frmPropertyDetails;
  72. var error = "";
  73. if (form.property_name.value=="") error+="Please enter a property name\n";
  74. if (form.location_name.value=="") error+="Please select the location name of your property\n";
  75. if (form.acc_type.value=="") error+="Please select accomodation type of your peoperty\n";
  76. if (form.street_address.value=="") error+="Please enter the street address of your property\n";
  77. if (form.owner.value=="") error+="Please select authority\n"
  78.  
  79. if(error !="") {
  80. alert(error);
  81. return false;
  82. }
  83. else {
  84. document.form.submit();
  85. }
  86. }
  87. </script>
  88. </head>
  89.  
  90. <body>
  91. <div id="container">
  92. <?php include('includes/header.php'); ?>
  93. <div id="wrapper">
  94. <div id="content" style="border:1px solid #ccc;">
  95. <div id="rightnow">
  96. <h3 class="reallynow">
  97. <span>Property Details</span>
  98. <br />
  99. </h3>
  100. <p>Use this page to update your property details. </p>
  101. <div class="usethis">Please note that any changes made will take up to 15 minutes to appear on Consumer sites. </div>
  102. </div>
  103. <form name="frmPropertyDetails" id="frmPropertyDetails" action="" method="post" onsubmit="return chk();" >
  104. <input type="hidden" value="save" name="action" />
  105. <?php if ($error_msg) {?>
  106. <div class="error_message">* Please complete all required fields<?php echo $error_msg;unset($error_msg) ?></div>
  107. <?php } ?>
  108. <?php
  109. if (isset($_SESSION['msg'])){
  110. echo '<div class="success_message">* Property details saved successfully<br/><span class="nos">Your property details have been saved. Make any additional changes below, or select another menu item from the left. </span></div>';
  111. unset($_SESSION['msg']);
  112. }
  113. ?>
  114. <table width="734" border="0" cellpadding="3" cellspacing="0" style="margin-top:10px;">
  115. <tr>
  116. <td height="32" colspan="3" valign="top"><strong>Location Details</strong> </td>
  117. </tr>
  118. <tr class="row0">
  119. <td width="190" align="right">*Loation:</td>
  120. <td width="313"><label>
  121. <?php $location = $db->fnSelect('tbl_hotel_location','*','status=1 order by id');?>
  122. <select name="location_name" id="location_name" style="width:260px;">
  123. <option value="">:: Select property location ::</option>
  124. <?php if ($location) { foreach ($location as $key=>$loc) { ?>
  125. <?php $fi = trim($loc['zone'].'::'.$loc['town']);
  126. echo $fiedit = trim($rs1[0]['location_zone'].'::'.$rs1[0]['location_area']);
  127. ?>
  128. <option value="<?php echo $fi; ?>" <?php if($fi==$fiedit) { ?> selected="selected" <?php } ?>><?php echo $loc['zone'].'::'.$loc['town']; ?></option>
  129. <?php }} ?>
  130. </select>
  131. </label></td>
  132. <td width="213" align="right">&nbsp;</td>
  133. </tr>
  134. <tr>
  135. <td align="right">Beach: </td>
  136. <td><input name="beach" type="text" value="<?php echo $rs1[0]['beach']; ?>" size="39" maxlength="100" /></td>
  137. <td align="right">Max 100 characters </td>
  138. </tr>
  139. <tr>
  140. <td align="right">&nbsp;</td>
  141. <td>&nbsp;</td>
  142. <td align="right">&nbsp;</td>
  143. </tr>
  144. <tr>
  145. <td height="33" colspan="3" align="left" valign="top"><strong>Property Details </strong></td>
  146. </tr>
  147. <tr class="row0">
  148. <td align="right">*Property Name: </td>
  149. <td><input type="text" name="property_name" id="property_name" size="50" value="<?php echo $rs1[0]['name']; ?>"/></td>
  150. <td align="right">&nbsp;</td>
  151. </tr>
  152. <tr>
  153. <td align="right">*Accomodation Type: </td>
  154. <td>
  155. <select name="acc_type">
  156. <option value="">:: Select accomodation type ::</option>
  157. <option value="House" <?php if ($rs1[0]['property_type']=='House') { ?> selected="selected"
  158. <?php } ?>>House</option>
  159. <option value="Apartment" <?php if ($rs1[0]['property_type']=='Apartment') { ?> selected="selected"
  160. <?php } ?>>Apartment</option>
  161. <option value="Bed & Breakfast" <?php if ($rs1[0]['property_type']=='Bed & Breakfast') { ?> selected="selected"
  162. <?php } ?>>Bed & Breakfast</option>
  163. <option value="Hotel" <?php if ($rs1[0]['property_type']=='Hotel') { ?> selected="selected"
  164. <?php } ?>>Hotel</option>
  165. <option value="Cottage" <?php if ($rs1[0]['property_type']=='Cottage') { ?> selected="selected"
  166. <?php } ?>>Cottage</option>
  167. </select></td>
  168. <td align="right">&nbsp;</td>
  169. </tr>
  170. <tr class="row0">
  171. <td align="right">*Street Address: </td>
  172. <td><input type="text" name="street_address" id="street_address" size="50" value="<?php echo $rs1[0]['address'] ?>"/></td>
  173. <td align="right">Not displayed to public</td>
  174. </tr>
  175. <tr>
  176. <td align="right">*Authority:</td>
  177. <td>
  178. <select name="owner" id="owner" style="width:260px;">
  179. <option value="">:: Select authority ::</option>
  180. <option value="Owner" <?php if ($rs1[0]['owner']=='Owner') { ?> selected="selected"
  181. <?php } ?>>Owner</option>
  182. <option value="Tourism officer" <?php if ($rs1[0]['owner']=='Tourism officer') { ?> selected="selected"
  183. <?php } ?>>Tourism officer</option>
  184. <option value="Onsite Manager" <?php if ($rs1[0]['owner']=='Onsite Manager') { ?> selected="selected"
  185. <?php } ?>>Onsite Manager</option>
  186. <option value="Real Estate Agent" <?php if ($rs1[0]['owner']=='Real Estate Agent') { ?> selected="selected"
  187. <?php } ?>>Real Estate Agent</option>
  188. </select> </td>
  189. <td align="right">&nbsp;</td>
  190. </tr>
  191. <tr class="row0">
  192. <td align="right">Web Site: </td>
  193. <td><input type="text" name="website_url" id="website_url" size="50" value="<?php echo $rs1[0]['website']; ?>"/></td>
  194. <td align="right">Not displayed to public</td>
  195. </tr>
  196.  
  197. <tr>
  198. <td height="33" colspan="3" align="left" valign="middle"><strong>Extra Details </strong></td>
  199. </tr>
  200. <tr>
  201. <td height="33" colspan="3" align="left" valign="top" class="td_feature">
  202. <table style="width:700px;" border='0' cellspacing='0' cellpadding='3'>
  203. <?php
  204. $edit_fs = array();
  205. $edit_fs = explode(",",$rs1[0]['features']);
  206. ?>
  207. <?php
  208. $features = $db->fnSelect('tbl_features','feature');
  209. $fi = count($features)/3;
  210. $j=0;
  211.  
  212. for ($i=$j;$i<$fi;$i++) {
  213. $x = $j+1;
  214. $y = $j+2;
  215. $class = ($i%2==0) ? 'row0' : '';
  216. echo "<tr width='500' class=$class>";
  217. if (!empty($features[$j][0])) {
  218. if (in_array($features[$j][0],$edit_fs)) {
  219. echo "<td><input name='chk[]' type='checkbox' checked='checked' value='".$features[$j][0]."'/>&nbsp;".$features[$j][0]."</td>";
  220. } else {
  221. echo "<td><input name='chk[]' type='checkbox' value='".$features[$j][0]."' />&nbsp;".$features[$j][0]."</td>";
  222. }
  223. }
  224. if (!empty($features[$x][0])) {
  225. if (in_array($features[$x][0],$edit_fs)) {
  226. echo "<td><input name='chk[]' type='checkbox' checked='checked' value='".$features[$x][0]."' />&nbsp;".$features[$x][0]."</td>";
  227. } else {
  228. echo "<td><input name='chk[]' type='checkbox' value='".$features[$x][0]."' />&nbsp;".$features[$x][0]."</td>";
  229. }
  230. }
  231. if (!empty($features[$y][0])) {
  232. if (in_array($features[$y][0],$edit_fs)) {
  233. echo "<td><input name='chk[]' type='checkbox' checked='checked' value='".$features[$y][0]."' />&nbsp;".$features[$y][0]."</td>";
  234. } else {
  235. echo "<td><input name='chk[]' type='checkbox' value='".$features[$y][0]."' />&nbsp;".$features[$y][0]."</td>";
  236. }
  237. }
  238. echo "</tr>";
  239. $j=$j+3;
  240. }
  241.  
  242. ?>
  243. </table> </td>
  244. </tr>
  245. <tr>
  246. <td colspan="3" align="center"> </td>
  247. </tr>
  248.  
  249. <tr>
  250. <td align="left"><label>
  251. <input type="submit" name="Submit" value="save property details" />
  252. </label></td>
  253. <td>&nbsp;</td>
  254. <td align="right">&nbsp;</td>
  255. </tr>
  256. <tr>
  257. <td align="right">&nbsp;</td>
  258. <td>&nbsp;</td>
  259. <td align="right">&nbsp;</td>
  260. </tr>
  261. </table>
  262. </form>
  263. </div>
  264. <?php include("includes/sidebar.php"); ?>
  265. </div>
  266. <div id="footer">
  267. <div id="credits">
  268. &copy;Copyright <a target="_blank" href="http://www.goaseahomes.com">Goaseahomes</a> all rights reserved
  269. </div>
  270. <br />
  271.  
  272. </div>
  273. </div>
  274. </body>
  275. </html>
Last edited by itsrahulk; Oct 27th, 2009 at 7:35 am.
Rahul K

They say, its not possible. Well it is, and relatively easy to accomplish!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #2
Oct 27th, 2009
its very natural, if you unset some variable using unset($var_name) function, its value disappears.so don't use it if you don't want to reset the variable
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 23
Reputation: itsrahulk is an unknown quantity at this point 
Solved Threads: 0
itsrahulk itsrahulk is offline Offline
Newbie Poster
 
0
  #3
Oct 27th, 2009
as i am taking message in the session variable so i need to unset it after message display so that it can not appear when i will come back from other pages as well.

Originally Posted by network18 View Post
its very natural, if you unset some variable using unset($var_name) function, its value disappears.so don't use it if you don't want to reset the variable
Last edited by itsrahulk; Oct 27th, 2009 at 7:49 am.
Rahul K

They say, its not possible. Well it is, and relatively easy to accomplish!
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC