Enjoy an ad free experience by logging in. Not a member yet?
Register .
10-23-2012, 05:59 PM
PM User |
#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!
Quote:
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 -> name , 0 , 40 ); 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
}
?>
10-23-2012, 06:09 PM
PM User |
#2
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 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.
10-23-2012, 06:22 PM
PM User |
#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!
10-23-2012, 06:25 PM
PM User |
#4
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 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.
10-23-2012, 07:08 PM
PM User |
#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!
10-23-2012, 08:08 PM
PM User |
#6
New to the CF scene
Join Date: Oct 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Run SQL query/queries on database
Quote:
`items_id``image`SELECT * FROM `item_images` WHERE 1
Is there an error with that at all?
10-23-2012, 08:11 PM
PM User |
#7
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 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.
10-23-2012, 08:15 PM
PM User |
#8
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Quote:
Originally Posted by
Uniqueconcepts
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.
10-23-2012, 08:45 PM
PM User |
#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-23-2012, 11:55 PM
PM User |
#10
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 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.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 05:14 AM .
Advertisement
Log in to turn off these ads.