Answer the question
In order to leave comments, you need to log in
Where is the error in reading using the POST method?
I can’t understand where I’m wrong ...
There is a form (Bootstrap 4) that includes a request and update of data (there are, in general, 5 fields + a button, I will show one field, the rest are similar):
<form role="form" name="GlobalsForm" action="" method="post">
<?php global_data_read (); ?> <!-- Читаем данные из БД -->
<div class="form-group row h-20">
<label for="site-name-input" class="col-2 col-form-label my-auto">Заголовок сайта</label>
<div class="col-5 my-auto">
<input class="form-control site-name" type="text" name="SiteName" value="<?php echo $GlobalData['SiteName']; ?>" id="site-name-input">
</div>
<span id="site-name-input" class="text-muted my-auto">Заголовок сайта. Применяется в названии вкладки браузера</span>
</div>
<button type="submit" name="submit" id="globals-data-save" class="btn btn-success btn-lg pull-right ">Сохранить общие настройки</button>
<?php global_data_update (); ?> <!-- Изменяем данные в БД -->
</form>
function global_data_read () {
global $GlobalData;
$GlobalData = array();
$bd_link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno()) {
printf("Не удалось подключиться: %s\n", mysqli_connect_error());
exit();
}
if (!$bd_link->set_charset("utf8")) {
printf("Ошибка при загрузке набора символов utf8: %s\n", $bd_link->error);
exit();
}
$globals_query = "SELECT * FROM site_data";
$globals_result = $bd_link->query($globals_query);
while($globals_row = $globals_result->fetch_array()) {
$globals_rows[] = $globals_row;
$GlobalData['SiteName'] = $globals_row['SiteName'];
$GlobalData['CompanyName'] = $globals_row['CompanyName'];
$GlobalData['Theme'] = $globals_row['Theme'];
$GlobalData['Phone'] = $globals_row['Phone'];
$GlobalData['Email'] = $globals_row['Email'];
}
return $GlobalData;
}
function global_data_update () {
$bd_link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno()) {
printf("Не удалось подключиться: %s\n", mysqli_connect_error());
exit();
}
if (!$bd_link->set_charset("utf8")) {
printf("Ошибка при загрузке набора символов utf8: %s\n", $bd_link->error);
exit();
}
if (form_submitted()) {
$GlobalData['SiteName'] = $_POST['SiteName'];
echo "SiteName = " . $GlobalData['SiteName'] . "<br />";
$GlobalData['CompanyName'] = $_POST['CompanyName'];
echo "CompanyName = " . $GlobalData['CompanyName'] . "<br />";
$GlobalData['Theme'] = $_POST['Theme'];
echo "Theme = " . $GlobalData['Theme'] . "<br />";
$GlobalData['Phone'] = $_POST['Phone'];
echo "Phone = " . $GlobalData['Phone'] . "<br />";
$GlobalData['Email'] = $_POST['Email'];
echo "Email = " . $GlobalData['Email'];
$globals_query = "UPDATE site_data SET
SiteName = '" . $GlobalData['SiteName'] . "',
CompanyName = '" . $GlobalData['CompanyName'] . "',
Theme = '" . $GlobalData['Theme'] . "',
Phone = '" . $GlobalData['Phone'] . "',
Email = '" . $GlobalData['Email'] . "'";
$globals_result = $bd_link->query($globals_query);
}
return $GlobalData;
}
Answer the question
In order to leave comments, you need to log in
Try this: $GlobalData['Theme'] = isset($_POST['Theme']) ? $_POST['Theme'] : '';
And the error says that you are referring to a non-existent index, that is, the 'Theme' index does not exist in the $GlobalData array
PS: maybe there is some letter from Cyrillic instead of Latin, what the hell is not joking
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question