0

hi all,

i am creating a session variable on the property_detail.php page

where after updating all the values i redirected the use to the same page with the value in the session to be printed on the same page
as "Property details saved successfully".

but the problem is when i use redirect and prints the value of the
session like this.

echo $_session['msg']"; unset($_session['msg'])

i want to remove the session after displaying the message to the user. but when i removes the

unset($_session['msg'])

the message is being appear on the same page.

but with

unset

it's not running.

Please help.

<?php if ($_SESSION['msg']) { ?>
<div class="success_message"><?php echo $_SESSION['msg']; if ($_SESSION['msg'])unset($_SESSION['msg']);?></div>
 <?php } ?>
<?php
/* check sesison */
require_once('chksession.php');
require_once ('includes/dbconfig.php');
/* get all the details of property */
$rs1 = $db->fnSelect('tbl_hotel','*','id='.$_SESSION['pid']) or die('There is some technical problem');
?>
<?php
	/* update all the property details */
	if ($_POST['action']=='save') {
		/** check all the values those are required on the server side */
		require_once('includes/class/validation.class.php');
		$location  = htmlspecialchars(strip_tags($_POST['location_name']));
		$beach     = htmlspecialchars(strip_tags($_POST['beach']));
		$propertyname = htmlspecialchars(strip_tags($_POST['property_name']));
		$acc_type  = htmlspecialchars(strip_tags($_POST['acc_type']));
		$address   = htmlspecialchars(strip_tags($_POST['street_address']));
		$owner     = htmlspecialchars(strip_tags($_POST['owner']));
		$website_url  = htmlspecialchars(strip_tags($_POST['website_url']));
		$t = "NOW()";
		
		/* initialize obj object for validation */
		$obj = new PhpServerValidation();
		$obj->fnGetFields($location,'req','Location name is required');
		$obj->fnGetFields($propertyname,'req','Property name is required');
		$obj->fnGetFields($acc_type,'req','Accomodation Type is required');	
		$obj->fnGetFields($address,'req','Steet Address is required');	
		$obj->fnGetFields($owner,'req','Authority is required');	
		
		/* validate all the fields */
		$error = $obj->fnFieldsvalidation();
		
		/* if there is an error display it out */
		if (!empty($error)) {
			$error_msg = '<UL>'.$error.'</UL>';
		} 
		/* update all the fields */
		else {
			$loc = array();
			$loc = explode("::",$location);
			/* check if checkboxes values are preset */
			if ($_POST['chk']) {
				/* make a string of all the features */
				$fe = implode(",",$_POST['chk']);
			 } else {
				$fe = '';
			 }
			$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";
			$condition = 'id='.$_SESSION['pid'];
			//update the values into table
			$outputupdate = $db->fnUpadte('tbl_hotel',$fields,$condition);
			if ($outputupdate) {
				$_SESSION['msg'] = "* Property details updated successfully";
				header('location:property_details.php?pid='.$_SESSION['pid']);
			}
		}
	}
?>
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by itsrahulk
0

Hey.

No offense, but that first code snipped is some ugly looking code :-]

Always write your code like the person, who's job it is to debug it, is a mad heavy-weight boxer with an anger-management problem. (The first thing I was told when I started learning programming. As it turns out, saved me a lot of pain later on xD)

Try to change it to:

<?php
if (isset($_SESSION['msg']))
{
    echo '<div class="success_message">', $_SESSION['msg'], '</div>';
    unset($_SESSION['msg']);
} 
?>

When you write your code clearly like that, it's much easier to spot syntax errors, like quote-mismatches and missing semi-colons.

0

it's not working. if i am writing unset($_session) after echo $_session. message is not being appear.


please help me.

Hey.

No offense, but that first code snipped is some ugly looking code :-]

Always write your code like the person, who's job it is to debug it, is a mad heavy-weight boxer with an anger-management problem. (The first thing I was told when I started learning programming. As it turns out, saved me a lot of pain later on xD)

Try to change it to:

<?php
if (isset($_SESSION['msg']))
{
    echo '<div class="success_message">', $_SESSION['msg'], '</div>';
    unset($_SESSION['msg']);
} 
?>

When you write your code clearly like that, it's much easier to spot syntax errors, like quote-mismatches and missing semi-colons.

Edited by itsrahulk: n/a

0

Ok, I see.

The code I posted does work. It's to simple, really, for it not to work. If it isn't working, there is something happening around it that is interfering. Is there possibly something in front of the part that prints the message that unsets it?

Could you post the whole page, including the code that would print the message? Maybe we can spot the problem if we can see it all.

On a side-note, why do you use sessions and re-directs to print the success message?
Couldn't you just do something like:

<?php
$successMessage = "";

if(isset($_POST['element'])) {
    // Process the form
    // ...

    if(1/* Form successfully processed */) {
        $successMessage = '<div id="SuccessMessage">Success message</div>';
    }
}
?>
<!DOCTYPE html>
<html>
    <head><title>Example</title></head>
    <body>
        <?php echo $successMessage; ?>
    </body>
</html>
0

the code you given below works and message is being appear.
i have applied this before using session but i am not getting refreshed values which i updated to database without resending header.

Ok, I see.

The code I posted does work. It's to simple, really, for it not to work. If it isn't working, there is something happening around it that is interfering. Is there possibly something in front of the part that prints the message that unsets it?

Could you post the whole page, including the code that would print the message? Maybe we can spot the problem if we can see it all.

On a side-note, why do you use sessions and re-directs to print the success message?
Couldn't you just do something like:

<?php
$successMessage = "";

if(isset($_POST['element'])) {
    // Process the form
    // ...

    if(1/* Form successfully processed */) {
        $successMessage = '<div id="SuccessMessage">Success message</div>';
    }
}
?>
<!DOCTYPE html>
<html>
    <head><title>Example</title></head>
    <body>
        <?php echo $successMessage; ?>
    </body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.