Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error in SQL syntax

    I get this error message whenever we try to add items. I'm not a PHP wizard, and I'm currently working on a website designed by two previous designers. Any help would be appreciated!

    A Database Error Occurred
    Error Number: 1064

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    SELECT * FROM item_images WHERE items_id =

    PHP Code:
    <?php
    if (isset($items))
    {
        
    ?>
        <?if(count($items) > 0):?>
        <table class="no-arrow colstyle-alt rowstyle-alt onload-zebra">
            <tr>
                <th class="sortable">Name</th>
                <th class="sortable">SKU</th>
                <th class="sortable">Image</th>
                <th class="sortable">Conversion</th>
                <th class="sortable center">Featured</th>
                <th class="sortable">Category</th>
                <th class="icon"></th>
                <th class="icon"></th>
            </tr>
            <?foreach($items as $Item):?>
            <tr class="tr_link link" url="<?= site_url("/admin/items/create-group-item/$Item->groups_id/$Item->id"?>">
                <td><? echo substr($Item->name040); echo (strlen($Item->name) > 40) ? '...' '' ?></td>
                <td><?=$Item->sku?></td>
                <td><?=$Item->image?></td>
                <td><?= (isset($conversions[$Item->conversions_id])) ? $conversions[$Item->conversions_id]->name '' ?></td>
                <td class="center"><?= (!empty($Item->featured)) ? $Item->featured '' ?></td>
                <td>
                    <?php
                        
    if (isset($categories_dropdown))
                        {
                            echo 
    $categories_dropdown[$Item->categories_id];
                        }
                        else
                        {
                            echo 
    $categories[$Item->categories_id];
                        }
                    
    ?>
                </td>
                <td class="icon"><img src="<?php echo base_url();?>assets/images/admin/pencil-edit-icon.png" /></td>
                <td class="icon"><?=anchor('admin/items/item-delete/' $Item->id'<img src="' base_url() . 'assets/images/admin/delete-icon.png" />''class="delete"')?></td>
            </tr>
            <?endforeach?>
        </table>
        <?endif?>
        
        <script>
            $$('.delete').invoke('observe', 'click', function(e) {
                response = confirm('Are you sure you want to delete this item?');
                if(!response)
                    e.stop();
            });
        
            $$('.link').invoke('observe', 'click', function(e) {
                  window.location = $(this).readAttribute("url");
        
            });
        </script>

        <?php
    }
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You don't have the code for the SQL here, but the error itself indicates that it has not been provided with any items_id in which to search. Since you don't post the full error (as in PHP error), we can't show you where to look for it. Enable PHP's error reporting:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    It may tell you that you have undeclared variables.

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry for being so ignorant about this stuff, but where should I insert that line of code?

    Also, where can you generally find the SQL code? What would the extension be? Thank you so much for your help!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    SQL code can be embedded wherever in PHP code.
    Ini and error reporting sets are typically done at the top right after the <?php tags.

  • #5
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found some .sql files, and they say they're Server version 5.0.91. Could this be part of the problem?

    I looked to see if the error was simply changing TYPE= to ENGINE=, but it was already done.

    Not sure what part, if any, of this .sql coding I should paste here. Thanks!

  • #6
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Run SQL query/queries on database
    `items_id``image`SELECT * FROM `item_images` WHERE 1
    Is there an error with that at all?

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    In the first line of the code you showed you use if (isset($items)) but you never show us where $items came from. If you want help, *THAT* is what you must show.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    Quote Originally Posted by Uniqueconcepts View Post
    Is there an error with that at all?
    How can we tell when you don't show us WHERE it is being used?

    The actual SQL that you show there is unusual but not illegal.

    But it doesn't match the error message you gave in your first message. So it may be entirely irrelevant.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think my complete lack of php and SQL knowledge is making this hard to solve. Thank you guys, but I think I'll have to hire somebody else to work this out!

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    You can't show more of the PHP coding???

    Or is this page being generated by some kind of tool that generates the PHP for you?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •