php - SQL insert into select issue -
so think i'm close figuring out query won't add item "pending" table "items" table. can guys me out please. if want delete after gets added should add code below insert select query? thanks
action.php:
$sql = "insert items (photo,title,description, name) select (photo,title,description, name) pending"; $stmt = $conn->prepare($sql); $stmt->execute();
example delete query after takes item "pending" items:
$idtodelete = filter_var($_post["recordtodelete"],filter_sanitize_number_int); //try deleting record using record id received post $sql = "delete pending id = :id"; $stmt = $conn->prepare($sql); $stmt->bindparam(':id', $idtodelete, pdo::param_int); $stmt->execute();
i think leaving open mistakes doing way.
consider happen if new row added pending queue after have issued insert select
before have started delete.
i think need in more controlled way inside single loop make sure deleting have copied pending
items
.
$sql = "select photo,title,description, name pending"; $select_pending = $conn->prepare($sql); $select_pending->execute(); $sql = "insert items (photo,title,description, name) values (:photo,:title,:description, :name)"; $insert_items = $conn->prepare($sql); $sql = "delete pending id = :id"; $delete_pending = $conn->prepare($sql); // if using innodb databases. //$conn->begintransaction(); while( $row = $select_pending->fetch_object() ) { $insert_items->bindparam(':photo', $row->photo, pdo::param_str); $insert_items->bindparam(':title', $row->title, pdo::param_str); $insert_items->bindparam(':description', $row->description, pdo::param_str); $insert_items->bindparam(':name', $row->name, pdo::param_str); $insert_items->execute(); $delete_pending->bind_param(':id', $row->id, pdo::param_int); $delete_pending->execute(); } // if using innodb databases. //$conn->commit();
Comments
Post a Comment