prasant Posted June 30, 2017 Posted June 30, 2017 i want to updating multiple post in cms, draft to published, published to draft. there are error showing is QUERY FAILED .You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'on' at line 1 <?php if(isset($_POST['checkBoxArray'])) { foreach($_POST['checkBoxArray'] as $postValueId ) { $bulk_options = $_POST['bulk_options']; switch($bulk_options) { case 'published' : $query = "UPDATE posts SET post_status = '{$bulk_options}' WHERE post_id= {$postValueId} " ; $update_to_published_status = mysqli_query($connection,$query); confirmQuery($update_to_published_status); break; } } } ?> <form action="" method='post'> <table class="table table-bordered table-hover"> <div id="bulkOptionContainer" class="col-xs-4"> <select class="form-control" name="bulk_options" id=""> <option value="">Select Options</option> <option value="published">Publish</option> <option value="draft">Draft</option> <option value="delete">Delete</option> </select> </div> <div class="col-xs-4"> <input type="submit" name="submit" class="btn btn-success" value="Apply"> <a class="btn btn-primary" href="add_post.php"?>Add New</a> </div> <thead> <tr> <th><input id="selectAllBoxes" type="checkbox"></th> <th>ID</th> <th>tilte</th> <th>Category</th> <th>image</th> <th>content</th> <th>date</th> <th>tags</th> <th>comment count</th> <th>status</th> <th>Edit</th> <th>Delete</th> </tr> </thead> <tbody> <?php $query = "SELECT * FROM posts"; $select_post= mysqli_query($connection,$query); while($row = mysqli_fetch_assoc($select_post)) { $post_id = $row['post_id']; $post_title = $row['post_title']; $post_category_id = $row['post_category_id']; $post_image = $row['post_image']; $post_content = $row['post_content']; $post_date = $row['post_date']; $post_tags = $row['post_tags']; $post_comment_count = $row['post_comment_count']; $post_status = $row['post_status']; echo "<tr>"; ?> <td><input class='checkBoxes' type='checkbox' name='checkBoxArray[]' vlaue='<?php echo $post_id; ?>'></td> <?php echo "<td>$post_id</td>"; echo "<td>$post_title</td>"; $query = "SELECT * FROM categories WHERE cat_id = {$post_category_id} "; $select_categories_id = mysqli_query($connection,$query); while($row = mysqli_fetch_assoc($select_categories_id)) { $cat_id = $row['cat_id']; $cat_title = $row['cat_title']; echo "<td>{$cat_title}</td>"; } echo "<td><img width='100' src='../images/$post_image' alt='image'</td>"; echo "<td>$post_content</td>"; echo "<td>$post_date</td>"; echo "<td>$post_tags</td>"; echo "<td>$post_comment_count</td>"; echo "<td>$post_status</td>"; echo "<td><a href='posts.php?source=edit_post&p_id={$post_id}'>Edit</a></td>"; echo "<td><a href='posts.php?delete={$post_id}'>Delete</a></td>"; echo "</tr>"; } ?> </tbody> </table> </form> <?php if(isset($_GET['delete'])){ $the_post_id = $_GET['delete']; $query = "DELETE FROM posts WHERE post_id = {$the_post_id} "; $delete_query = mysqli_query($connection, $query); header("Location: posts.php"); } ?> Please help !!!! thanks Share this post Link to post Share on other sites More sharing options...
PRO ISP Jon Eivind Posted June 30, 2017 Posted June 30, 2017 Hi prasant and welcome to the forum, If you would add a code line outputting the query so that we could see the query it might be more apparent what the mistake would be. Could you do that and supply us the query? Share this post Link to post Share on other sites More sharing options...
prasant Posted June 30, 2017 Posted June 30, 2017 Thank you very much Eivind for earlier response.... i want to update the checkbox post draft to published, or published to draft. Share this post Link to post Share on other sites More sharing options...
PRO ISP Jon Eivind Posted June 30, 2017 Posted June 30, 2017 Hi again, Could you change this code: $query = "UPDATE posts SET post_status = '{$bulk_options}' WHERE post_id= {$postValueId} " ; To: $query = "UPDATE posts SET post_status = '{$bulk_options}' WHERE post_id= {$postValueId} " ; echo $query: And then paste to us the string that probably will appear somewhere in the page? Share this post Link to post Share on other sites More sharing options...
prasant Posted June 30, 2017 Posted June 30, 2017 7 minutes ago, PRO ISP Jon Eivind said: still getting error : Parse error: syntax error, unexpected '$query' (T_VARIABLE) in /Applications/XAMPP/xamppfiles/htdocs/CMS/admin/includes/view_all_posts.php on line 17 <?php if(isset($_POST['checkBoxArray'])) { foreach($_POST['checkBoxArray'] as $postValueId ) { $bulk_options = $_POST['bulk_options']; switch($bulk_options) { case 'published' : $query = "UPDATE posts SET post_status = '{$bulk_options}' WHERE post_id= {$postValueId} " ; echo $query: $update_to_published_status = mysqli_query($connection,$query); confirmQuery($update_to_published_status); break; } } } ?> <form action="" method='post'> <table class="table table-bordered table-hover"> <div id="bulkOptionContainer" class="col-xs-4"> <select class="form-control" name="bulk_options" id=""> <option value="">Select Options</option> <option value="published">Publish</option> <option value="draft">Draft</option> <option value="delete">Delete</option> </select> </div> <div class="col-xs-4"> <input type="submit" name="submit" class="btn btn-success" value="Apply"> <a class="btn btn-primary" href="add_post.php"?>Add New</a> </div> <thead> <tr> <th><input id="selectAllBoxes" type="checkbox"></th> <th>ID</th> <th>tilte</th> <th>Category</th> <th>image</th> <th>content</th> <th>date</th> <th>tags</th> <th>comment count</th> <th>status</th> <th>Edit</th> <th>Delete</th> </tr> </thead> <tbody> <?php $query = "SELECT * FROM posts"; $select_post= mysqli_query($connection,$query); while($row = mysqli_fetch_assoc($select_post)) { $post_id = $row['post_id']; $post_title = $row['post_title']; $post_category_id = $row['post_category_id']; $post_image = $row['post_image']; $post_content = $row['post_content']; $post_date = $row['post_date']; $post_tags = $row['post_tags']; $post_comment_count = $row['post_comment_count']; $post_status = $row['post_status']; echo "<tr>"; ?> <td><input class='checkBoxes' type='checkbox' name='checkBoxArray[]' vlaue='<?php echo $post_id; ?>'></td> <?php echo "<td>$post_id</td>"; echo "<td>$post_title</td>"; $query = "SELECT * FROM categories WHERE cat_id = {$post_category_id} "; $select_categories_id = mysqli_query($connection,$query); while($row = mysqli_fetch_assoc($select_categories_id)) { $cat_id = $row['cat_id']; $cat_title = $row['cat_title']; echo "<td>{$cat_title}</td>"; } echo "<td><img width='100' src='../images/$post_image' alt='image'</td>"; echo "<td>$post_content</td>"; echo "<td>$post_date</td>"; echo "<td>$post_tags</td>"; echo "<td>$post_comment_count</td>"; echo "<td>$post_status</td>"; echo "<td><a href='posts.php?source=edit_post&p_id={$post_id}'>Edit</a></td>"; echo "<td><a href='posts.php?delete={$post_id}'>Delete</a></td>"; echo "</tr>"; } ?> </tbody> </table> </form> <?php if(isset($_GET['delete'])){ $the_post_id = $_GET['delete']; $query = "DELETE FROM posts WHERE post_id = {$the_post_id} "; $delete_query = mysqli_query($connection, $query); header("Location: posts.php"); } ?> Share this post Link to post Share on other sites More sharing options...
prasant Posted June 30, 2017 Posted June 30, 2017 Please check below : i think error is here : not picking the $post_id echo "<tr>"; ?> <td><input class='checkBoxes' type='checkbox' name='checkBoxArray[]' vlaue='<?php echo $post_id; ?>'></td> <?php spelling error of value anyway thank you very much.....Mr. eivind Share this post Link to post Share on other sites More sharing options...
PRO ISP Jon Eivind Posted June 30, 2017 Posted June 30, 2017 It seems I typed a colon instead of a semi colon which was my intention. Please change: echo $query: To: echo $query; What do you get then? Share this post Link to post Share on other sites More sharing options...
prasant Posted June 30, 2017 Posted June 30, 2017 Thank you very much Eivind.... <td><input class='checkBoxes' type='checkbox' name='checkBoxArray[]' vlaue='<?php echo $post_id; ?>'></td> i had solve this error..... there are spelling error of vlaue . it should be 'value' Share this post Link to post Share on other sites More sharing options...
PRO ISP Jon Eivind Posted June 30, 2017 Posted June 30, 2017 Great You're welcome! Share this post Link to post Share on other sites More sharing options...