0
I have the following code that saves reordering a list.
INDEX.PHP
<?php
    require_once ("Class.Drag.php");
    $auth_task = new Drag();
    $list_order = strip_tags($_POST['list_order']); 
    $res=$auth_task->update($list_order);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
<link rel="stylesheet" href="css/style.css" />
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui-1.10.4.custom.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
    <div class="container"> 
        <div class="content"> 
        <ul id="sortable">
            <?php 
                echo $auth_task->select();
            ?>
        </ul>
        </div><!-- content -->  
    </div><!-- container -->
</body>
</html>
CLASS.DRAP.PHP
public function update($list_order){
    $list = explode(',' , $list_order);
    $i = 1 ;
    foreach($list as $id) {
        try {
            $stmt = $this->conn->prepare('UPDATE items SET item_order = :item_order WHERE id = :id');
            $stmt->bindParam(':item_order', $i, PDO::PARAM_INT);
            $stmt->bindParam(':id', $id, PDO::PARAM_INT);
            $stmt->execute();
        }catch (PDOException $exception){
        header("Location: ./error.php?err=Cant-Order");
        echo 'Erro: '.$exception->getMessage();
        return null;
    }
        $i++ ;
    }
}
SCRIPTDRAG.JS
$(function() {
    $('#sortable').sortable({
        axis: 'y',
        opacity: 0.7,
        handle: 'span',
        update: function(event, ui) {
            var list_sortable = $(this).sortable('toArray').toString();         
            $.ajax({
                url: 'index.php',
                type: 'POST',                
                data: {list_order:list_sortable},
                success: function(data) {
                    success_message('Gravado');
                },
                error: function(data){
                    failure_message('Erro');
                }
            });
        }
    });
});
Only that my post submission is empty, as I do not use
$list_order = strip_tags($_POST['list_order']); 
$res=$auth_task->update($list_order);
Have some way to send $list_order directly to class through ajax, without having to post on index.
'Cause you’ll always show up Notice: Undefined index: list_order, by empty post.
$_POSTto record is correct? where is sending his Ubmit? would not use$_GET?– KingRider
Which code snippet yielded the tags
<li>of the list?– Neuber Oliveira