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

9 innlegg i emnet

 

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

Del dette innlegget


Lenke til innlegg
Del på andre sider

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?

Del dette innlegget


Lenke til innlegg
Del på andre sider

Thank you very much  Eivind for earlier response....

i want to update the checkbox post draft to published, or published to draft.

 

Screen Shot 2017-06-30 at 11.37.02 AM.png

Screen Shot 2017-06-30 at 11.37.32 AM.png

Del dette innlegget


Lenke til innlegg
Del på andre sider

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?

Del dette innlegget


Lenke til innlegg
Del på andre sider
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");

    }

    ?>
 

 

Del dette innlegget


Lenke til innlegg
Del på andre sider

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

Del dette innlegget


Lenke til innlegg
Del på andre sider

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?

Del dette innlegget


Lenke til innlegg
Del på andre sider

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'

 

 

Del dette innlegget


Lenke til innlegg
Del på andre sider

Great :) You're welcome!

Del dette innlegget


Lenke til innlegg
Del på andre sider

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!


Start en konto

Logg inn

Har du allerede en konto? Logg inn her.


Logg inn nå