MySQL Error

I keep on getting an error when I try to update my cart or checkout after already being logged in. The error I am receiving is:


[QUOTE]Database error: 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 ‘WHERE user_id=‘1’ AND type=‘C’’ at line 1

Invalid query: DELETE FROM WHERE user_id=‘1’ AND type=‘C’[/QUOTE]



Here is a screen shot of the whole error:







If anyone can help I would really appreciate it.



Brandon

I can’t see the user ID being 1 and type C being customer if your an admin…

Would be worth creating a new admin account, deleteing your old and seeing if that works.



Sound as though you’ve got minor damage to that table mentioned.

Might also be worth attempting to ‘repair database’ if you have this option available using cPanel (hosting)

I set up a new user and this problem still happened. I also restored my database to an earlier one and I still had this problem. I am now thinking about restoring the database to an even earlier time, but I then have to figure out how to restore my products I have recently added. Unfortunately I don’t know when this problem begain so I don’t know how far back to go on the restoration. I also plan on upgrading to version 1.3.5 when a stable version is released so if the upgrade will fix this problem than I might just leave it until then. If anyone else has any ideas I would really appreciate hearing them.



Brandon

I don’t think you understood what I ment.



Create a new ADMIN user



Via SQL Database, Deleted the USER ID = 1 (the ‘god admin account’)

Then change the newly created admin’s ID to 1.



Not saying it will work, but there’s a fair chance it will

Jesse



Not to sound like I have know idea what I am doing, but how would I go about deleting the admin account through my SQL Database? I exported the cscart_user table and edited it in Excel, but when I imported it back into my database I just lost the whole table all together. I ended up having to restore my whole database to one that was a backup from a couple of days ago. I also tried opening the entire database with excel, but it ended up giving me a “file not loaded completely” message because of the size of my database. Also when trying to save just the user table I got an error saying that some features are not compatible with the text (tab deliminated) format. I don’t really know what these errors mean or what to do about them. If you have any suggestions on how I could go about editing my database file I would really like to hear them. Thank you for your time.



Brandon

Load your old database up,



Using PHPMYADMIN



→ Select the Database

–>Click on “cscart_users”

—>Click on “Browse” tab



+++++++++++++

I’m having trouble with my own PHPMyAdmin atm, so bear with the instructions best you can

+++++++++++++



Find the table that correspondes to User ID 1, click on the checkbox next to it and click on the export tab.



Hopefully this will provide you with a few lines of code to be inserted/uploaded into your current database.



Jesse

O.K. I finally figured out how to change the users, but it had no effect and I still get the same error. I now only have just the one new admin user. Any more ideas?



Brandon

The query, DELETE FROM WHERE user_id=‘1’ AND type=‘C’ is incomplete



There should be a table listed in between FROM and WHERE



example:



DELETE FROM table1 WHERE user_id=‘1’ AND type=‘C’

Scott



Unfortunately I have no clue about what you are saying and how to fix it. Could you please explain what I would need to do to fix this error?



Brandon

This is probably either caused by a corrupted or modified file Brandon so no way to explain a proper fix.



I am looking thru your files now via FTP to see if I can find the issue.



Have you added any mods or edited any files recently? I see many files within your cart have a modification date of 09/14 and 09/15. This could help to track this down.

Ok this problem seems to be caused by the file core/fn_cart.php @ function fn_save_cart_content on line #373



Looking thru this file it appears to have been modified for some hack or modification you have had done. Try backing it up then replacing it with an original file and see if it resolves the cart problem.



Note, this might also create other problems because it will be removing edits that the modification needs.

I’ll try that. Thank you very much Scott.



Brandon

Well I’m not really sure what I did is right, but I figured out that the error was caused from when I added the Gift Certificate mod to my site. I decided to just remove this code and replace it with the original. I am no longer able to sell gift ceritificates, but at least people can check out now. I also just figure I’ll wait to mess around with gift certificates when 1.3.5 comes out since it is built in.



Thank you guys for all your help I really appreciate it.



Brandon

Was that code added to the function I mentioned above?

This was the code I removed:


function fn_save_cart_content(&$cart, $user_id, $mode = 'cart', $type = 'C')
{
global $db_tables;

if (!empty($user_id)) {
db_query("DELETE FROM $db_tables[user_session_products] WHERE user_id='$user_id' AND type='$type'");
$_cart = '';
if (!empty($cart['products'])) {
$_cart = addslashes(serialize($cart['products']));
}
if ($mode != 'cart') {
//fn_print_r($mode,"UPDATE $db_tables[users] SET $mode='$_cart' WHERE user_id='$user_id'");
db_query("UPDATE $db_tables[users] SET $mode='$_cart' WHERE user_id='$user_id'");
} else {
db_query("UPDATE $db_tables[users] SET cart_content='$_cart' WHERE user_id='$user_id'");
}

$_cart_prods = $cart['products'];
if (!empty($_cart_prods)) {
foreach ($_cart_prods as $_item_id => $_prod) {
$_cart_prods[$_item_id]['user_id'] = $user_id;
$_cart_prods[$_item_id]['timestamp'] = TIME;
$_cart_prods[$_item_id]['type'] = $type;
$_cart_prods[$_item_id]['item_id'] = $_item_id;
$_cart_prods[$_item_id]['item_type'] = 'P';
$_cart_prods[$_item_id]['extra'] = addslashes(serialize($_prod));
$_cart_prods[$_item_id]['amount'] = empty($_cart_prods[$_item_id]['amount']) ? 1 : $_cart_prods[$_item_id]['amount'];
$_cart_prods[$_item_id] = fn_check_table_fields($_cart_prods[$_item_id], $db_tables['user_session_products']);
if (!empty($_cart_prods[$_item_id])) {
db_insert_by_array($db_tables['user_session_products'], $_cart_prods[$_item_id]);
}
}
}
global $core_dir;
$function = __FUNCTION__;
include $core_dir.'addons_inheritance.php';

}

return true;
}




I replaced it with:


function fn_save_cart_content(&$cart, $user_id, $mode = 'cart')
{
global $db_tables;

if (!empty($user_id)) {
$_cart = '';
if (!empty($cart['products'])) {
$_cart = addslashes(serialize($cart['products']));
}
if ($mode != 'cart') {
db_query("UPDATE $db_tables[users] SET $mode='$_cart' WHERE user_id='$user_id'");
} else {
db_query("UPDATE $db_tables[users] SET cart_content='$_cart' WHERE user_id='$user_id'");
}
}

return true;
}




Brandon

Thanks Brandon. I just wondered if I got the puzzle right :mrgreen:

Yes you did and if I would have actually read your post right the first time then the simple answer would have been “yes” instead of posting all of the code. Sorry about that.



Brandon