So yesterday I ran into this error which I can't seem to get a hang of. The piece of code below is supposed to make two posts in a recursive MariaDB table switch places.
$cid
is the ID of the post that is supposed to switch place, up or down.
$pid
is the parent ID.
$ord
is which place the post has under the parent.
$dir
is in which direction the post is supposed to be moved, up or down.
Then the post in the position that the first post is supposed to move to is taking the first posts initial place.
<?php
$cid = isset($_GET['cid']) ? $_GET['cid'] : "";
$pid = isset($_GET['pid']) ? $_GET['pid'] : "";
$ord = isset($_GET['ord']) ? $_GET['ord'] : "";
$dir = isset($_GET['dir']) ? $_GET['dir'] : "";
if($cid == "" || $pid == "" || $ord == "" || $dir == "") die('nu gick det åt pipsvängen...');
if($dir == "up") {
$opos = $ord--;
} elseif($dir == "down") {
$opos = $ord++;
} else {
die('ingen riktning');
};
$ostmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :onp WHERE foralder = :pid AND ordning = :oop");
$ostmt -> bindValue(":onp", $ord);
$ostmt -> bindValue(":pid", $pid);
$ostmt -> bindValue(":oop", $opos);
$ostmt -> execute();
$cstmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :cnp WHERE id = :cid");
$cstmt -> bindValue(":cnp", $opos);
$cstmt -> bindValue(":cid", $cid);
$cstmt -> execute();
?>
This does absolutely nothing. I doesn't change anything in the table and there are no errors whatsoever.