I have two arrays from form inputs that I am trying to combine and store in a single database cell. I am able to do this, but when trying to retrieve it, it gives a fatal error of exhausting the memory limit.
I am inserting a main slider basically that has additional slides within it. Kind of. I don't want to create individual sql tables, but maybe I need to.
My memory is at 256mb, I know I could increase it more but I'd rather figure out why it is so large.
So my Inputs are coming from:
<fieldset class="form-group">
<label class="label-top" for="scroll-content[]">Scroll Text #1</label>
<textarea rows="5" cols="50" name="scroll-content[]" id="scroll-content-"></textarea>
<input type="hidden" name="slide-number[]" value="1">
</fieldset>
<fieldset class="form-group">
<label class="label-top" for="scroll-content[]">Scroll Text #2:</label>
<textarea rows="5" cols="50" name="scroll-content[]" id="scroll-content-"></textarea>
<input type="hidden" name="slide-number[]" value="2">
</fieldset>
Inserting:
function add_new_scroll($dir, $plugin_id) {
// configure content array
$num = $_POST['slide-number'];
$array = $_POST['scroll-content'];
$combined = array_combine($num, $array);
$content = json_encode($combined);
// global connection
global $conn;
wj_connect();
// sql
$sql = "INSERT INTO `scroll_text` (`scroll_order`, `num_slides`, `scroll_title`, `scroll_slug`, `scroll_content`)
VALUES(?,?,?,?,?)
ON DUPLICATE KEY UPDATE
`scroll_order` = VALUES(`scroll_order`),
`num_slides` = VALUES(`num_slides`),
`scroll_title` = VALUES(`scroll_title`),
`scroll_slug` = VALUES(`scroll_slug`),
`scroll_content` = VALUES(`scroll_content`)";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("iisss", $ansp_order, $ansp_num_slides, $ansp_title, $ansp_slug, $ansp_content);
// set params
$ansp_order = 0;
$ansp_num_slides = 1;
$ansp_title = $_POST['scroll-title'];
$ansp_slug = $_POST['scroll-slug'];
$ansp_content = $content;
$stmt->execute();
$stmt->close();
} else {
echo 'Scroll Text not added.';
}
$conn->close();
header("Location: ". $dir . "/scroll-text-admin.php?plug_id=" . $plugin_id . "&type=edit&slug=" . $ansp_slug);
}
Stores like:
{"1":"<p>1<\/p>","2":"<p>2<\/p>"}
Retrieving:
function return_scroll() {
// global connection
global $conn;
wj_connect();
// sql
$sql = "SELECT `id`, `scroll_order`, `num_slides`, `scroll_title`, `scroll_slug`, `scroll_content`
FROM `scroll_text` WHERE `scroll_slug` = ? LIMIT 1";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("s", $rsp_slug);
$rsp_slug = $_GET['slug'];
$stmt->execute();
// bind results
$stmt->bind_result($rsr_id, $rsr_order, $rsr_num_slides, $rsr_title, $rsr_slug, $rsr_content);
$scroll = array(
'id' => $rsr_id,
'order' => $rsr_order,
'num_slides' => $rsr_num_slides,
'title' => $rsr_title,
'slug' => $rsr_slug,
'content' => $rsr_content
);
$stmt->fetch();
$stmt->close();
}
$conn->close();
return $scroll;
}
Error!:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 4294967296 bytes) in /home/wonderadmin/public_html/wj-admin/plugins/scroll-text/scroll-text.php on line 199