R
R
Ratami Sato2015-12-09 12:51:36
PHP
Ratami Sato, 2015-12-09 12:51:36

How to update session after request?

How to refresh session
$_SESSION['site_color']
after request

header('Content-Type: text/html; charset=utf-8');
setlocale(LC_ALL,'ru_RU.65001','rus_RUS.65001','Russian_Russia.65001','russian');
    session_start();

//База
include ('../connect/config.php');
  
if (isset($_POST['update_color'])){
$site_color = stripslashes($site_color);
$site_color = htmlspecialchars($site_color);
$id=$_SESSION['id'];
$site_color = $_POST['site_color'];
$sql = ("UPDATE users SET site_color='$site_color' WHERE id='$id'");
$query = mysql_query($sql);
if (!$query){
die('updating error'. mysql_error());
}
else { echo 1; }
}
session_start();
$_SESSION['site_color'] = $query['site_color'];
header('Location: /settings.php');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-12-09
@reatachi_kun

At the end it should be like this ($site_color instead of $query['site_color']):

$_SESSION['site_color'] = $site_color;
header('Location: /settings.php');

PS: Why are you doing session_start() a second time?
PPS: Read PSR-2 , PDO .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question