I am using session_start() function in config.php file and this file is included in all files. in my add_page.php page, i am submitting a form and saving a message(in submit action) in the session, and then re-directing to index.php page(using header('location:...')). but after re-directing, i am not getting the message from the session. the other session data exist like-username, logged_in, etc. any idea???
Code bellow(add_news.php). after submitting form, it re-directs to news.php. config.php file has session_start() function at the top and it is included in every page:
<?php
include('../include/config.php');
//submit edit data
if (isset($_POST['submit_edit'])) {
$news_head = stripslashes(trim($_POST['news_head']));
$news_details = $_POST['news_details'];
$news_special = ($_POST['news_special']=='')?'0':'1';
$news_status = ($_POST['news_status']=='')?'0':'1';
$data = array('news_head'=>$news_head,
'news_details'=>$news_details,
'news_special'=>$news_special,
'news_status'=>$news_status);
$clause = "news_id = '".$_POST['news_id']."'";
$response = update_data('news', $data, $clause);
if($response)
$_SESSION['success_msg'] = "News updated successfully.";
}
//submit edit data end
?>
<form action="add_news.php" method="post" id="add_news_form">
<input type="hidden" name="news_id" value="<?php echo $news_id ?>" />
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td>News Heading</td>
<td><input type="text" name="news_head" id="news_head" class="required" value="<?php echo $news_head ?>" size="100" /></td>
</tr>
<tr>
<td>News Details</td>
<td><textarea name="news_details" id="news_details" class="editor required" rows="7" cols="60"><?php echo trim(stripslashes($news_details)); ?></textarea></td>
</tr>
<tr>
<td>Special News</td>
<td><input type="checkbox" name="news_special" id="news_special" value="1" <?php if($news_special=='1') echo 'checked="checked"'?> />
[ Checked means special ]</td>
</tr>
<tr>
<td>Status Status</td>
<td><input type="checkbox" name="news_status" id="news_status" value="1" <?php if($news_status=='1') echo 'checked="checked"'?> />
[ Checked means published ]</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit" <?php if($_REQUEST['news_id']!="" && $_REQUEST['action']=='edit') echo 'name="submit_edit"'; else echo 'name="submit"'; ?> /></td>
</tr>
</table>
</form>
session_write_close()calls in your code that could be closing the session before your form handler kicks in? - Marc B