Есть AJAX запрос:
$.ajax({
async: false,
url: "../php/blank_SOPe_show.php",
type: 'POST',
data: {
card_in_for_blank: card_in_for_blank,
enter_day_for_blank: enter_day_for_blank
},
success: function (data, textStatus, jqXHR) {
blank = 'SOPe';
tinyMCE.activeEditor.setContent('');
tinyMCE.execCommand('mceInsertContent', true, data);
$.toast({
text: "Запись 'ПЕРВИЧКА' в редакторе!",
heading: "ПРЕДУПРЕЖДЕНИЕ",
icon: "warning"
});
}
});
Есть PHP запрос
blank_SOPe_show.php.
<?php
include './connect.php';
$card_in_for_blank = htmlspecialchars($_POST['card_in_for_blank']);
$enter_day_for_blank = htmlspecialchars($_POST['enter_day_for_blank']);
$link = mysqli_connect($HOST, $USER, $PASS) or die(mysqli_errno($link));
mysqli_select_db($link, $SELECT_DB);
mysqli_set_charset($link, "UTF8");
if ($link) {
$stmt = mysqli_prepare($link, "SELECT s.text_blank FROM stories AS s, cards AS c WHERE s.card=c.id_card AND card_in='302' AND s.type_blank='SOPe' AND s.day_blank='06.03.2017'");
if ($stmt) {
mysqli_stmt_bind_param($stmt, "ss", $card_in_for_blank, $enter_day_for_blank);
/* запускаем запрос */
mysqli_stmt_execute($stmt);
/* связываем переменные с результатами запроса */
mysqli_stmt_bind_result($stmt, $text_blank);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
if ($text_blank) {
echo htmlspecialchars_decode($text_blank);
}
}
}
Таблица в БД была создана таким запросом:
CREATE TABLE `stories` (
`id_history` int(11) NOT NULL AUTO_INCREMENT,
`card` int(11) NOT NULL,
`type_blank` varchar(100) NOT NULL,
`day_blank` varchar(100) NOT NULL,
`text_blank` longtext NOT NULL,
PRIMARY KEY (`id_history`),
KEY `stories_cards_fk` (`card`),
CONSTRAINT `stories_cards_fk` FOREIGN KEY (`card`) REFERENCES `cards` (`id_card`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
Что удивительно, скрипт
blank_SOPe_add.php работает (он такой же, но только с командой INSERT INTO).
<?php
include './connect.php';
$card_in_for_blank = htmlspecialchars($_POST['card_in_for_blank']);
$card_out_for_blank = htmlspecialchars($_POST['card_out_for_blank']);
$number_ward_for_blank = htmlspecialchars($_POST['number_ward_for_blank']);
$patient_for_blank = htmlspecialchars($_POST['patient_for_blank']);
$birthday_for_blank = htmlspecialchars($_POST['birthday_for_blank']);
$enter_day_for_blank = htmlspecialchars($_POST['enter_day_for_blank']);
$doctor_for_blank = htmlspecialchars($_POST['doctor_for_blank']);
$diagnosis_for_blank = htmlspecialchars($_POST['diagnosis_for_blank']);
$mkb_for_blank = htmlspecialchars($_POST['mkb_for_blank']);
$text_blank = htmlspecialchars($_POST['text_blank']);
$link = mysqli_connect($HOST, $USER, $PASS) or die(mysqli_errno($link));
mysqli_select_db($link, $SELECT_DB);
mysqli_set_charset($link, "UTF8");
if ($link) {
$stmt = mysqli_prepare($link, "SELECT s.id_history FROM stories AS s, cards AS c WHERE s.card=c.id_card AND card_in=? AND s.type_blank=? AND s.day_blank=?");
if ($stmt) {
$type_blank = "SOPe";
mysqli_stmt_bind_param($stmt, "sss", $card_in_for_blank, $type_blank, $enter_day_for_blank);
/* запускаем запрос */
mysqli_stmt_execute($stmt);
/* связываем переменные с результатами запроса */
mysqli_stmt_bind_result($stmt, $id_history);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
if ($id_history) {
$healthy = array("История болезни №" . $card_in_for_blank, "а\к " . $card_out_for_blank, "Палата №" . $number_ward_for_blank, $patient_for_blank, $birthday_for_blank, $enter_day_for_blank . "г. ", $doctor_for_blank, $diagnosis_for_blank, "МКБ-Х: " . $mkb_for_blank);
$yummy = array("История болезни №['card_in']", "а\к ['card_out']", "Палата №['number_ward']", "['patient']", "['birthday']", "['enter_day']г. ", "['doctor']", "['diagnosis']", "МКБ-Х: ['mkb']");
$file = str_replace($healthy, $yummy, $text_blank);
$stmt = mysqli_prepare($link, "UPDATE stories SET text_blank=? WHERE id_history=? AND type_blank=?");
$type_blank = "SOPe";
mysqli_stmt_bind_param($stmt, "sss", $text_blank, $id_history, $type_blank);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
echo htmlspecialchars_decode($text_blank);
} else {
$healthy = array("История болезни №" . $card_in_for_blank, "а\к " . $card_out_for_blank, "Палата №" . $number_ward_for_blank, $patient_for_blank, $birthday_for_blank, $enter_day_for_blank . "г. ", $doctor_for_blank, $diagnosis_for_blank, "МКБ-Х: " . $mkb_for_blank);
$yummy = array("История болезни №['card_in']", "а\к ['card_out']", "Палата №['number_ward']", "['patient']", "['birthday']", "['enter_day']г. ", "['doctor']", "['diagnosis']", "МКБ-Х: ['mkb']");
$file = str_replace($healthy, $yummy, $text_blank);
$stmt = mysqli_prepare($link, "INSERT INTO stories (id_history, card, type_blank, day_blank, text_blank) VALUES (null, (SELECT id_card FROM cards WHERE card_in=?), ?, ?, ?)");
$type_blank = "SOPe";
mysqli_stmt_bind_param($stmt, "ssss", $card_in_for_blank, $type_blank, $enter_day_for_blank, $text_blank);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
echo htmlspecialchars_decode($text_blank);
}
}
}
Сам сайт изначально стоял на EasyPHP Win10 1607 15055.0, сейчас перекинул на RPi 3 Raspbian Jessie with PIXEL kernel 4.4.