R
R
Ratami Sato2015-12-08 12:25:33
PHP
Ratami Sato, 2015-12-08 12:25:33

How to take updated data from the database?

There is a color upgrade code

include ('../connect/config.php');
  
if (isset($_POST['update_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; }
}
header('Location: /');

How to make it so that after updating the data in the database, this updated data is displayed on the page?
And then they are updated when you go to the site

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri, 2015-12-08
@xtreme

I'm not a strong specialist in terms of code here, but ...
When executing update_color before querying the database (or after), force the user to reload the page (if it's not critical, which is long), or change the required block in CSS in the browser with Javascipt.

D
Dmitry Bay, 2015-12-08
@kawabanga

Your code is unsafe.
Imagine your code where $_POST['site_color'] = "123', username=(DELETE Users), id=1";

$site_color = $_POST['site_color'];
$sql = ("UPDATE users SET site_color='$site_color' WHERE id='$id'");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question