dcox
Posts: 29
|
| Posted: 11/11/2007, 4:12 PM |
|
Hi Guys/Gals,
I am trying to insert the current user into a table but not having any luck with my attempts. The latest is below. What is the proper syntax for MySQL and PHP 4?
// Create a new order
$SQL = "INSERT INTO store_orders (order_date, order_status_id, total, user_id) VALUES ("
.$db->ToSQL(date("Y-m-d"),ccsDate) . ",1,"
.$db->ToSQL($OrderTotal,ccsFloat)
.$db->ToSQL(CCSetSession("UserID", $db->f("user_id"))) . ")";
$db->query($SQL);
Thanks!
_________________
Toshiba Satellite X205 laptop, Intel(R) Core(TM)2 Duo CPU T7300 @ 2GHz, 4gb ram, Windows Vista Ultimate 32-bit, Dual 200gb 7200rpm hard drives (no raid), NVidia GeForce 8700M GT
|
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 11/11/2007, 10:37 PM |
|
dcox
I would echo out a copy of your $SQL to see if it is correct. Your SQL syntax appears to be correct. I would just verify that your input data is correct as well.
|
 |
 |
wkempees
|
| Posted: 11/12/2007, 3:02 AM |
|
$SQL = 'INSERT INTO store_orders (order_date, order_status_id, total,
user_id)
VALUES ('
. $db->ToSQL(date("Y-m-d"),ccsDate)
. ',1,'
. $db->ToSQL($OrderTotal,ccsFloat)
. CCGetUserID()
. ')' ;
$db->query($SQL);
assuming you want the currently logged in UserID.
|
|
|
 |
dcox
|
| Posted: 11/12/2007, 11:17 AM |
|
_________________
Thanks for your help!
---------------------------------------
Sent from YesSoftware forum http://forums.yessoftware.com/
|
|
|
 |
dcox
Posts: 29
|
| Posted: 11/12/2007, 11:28 AM |
|
Hi Guys,
I tried both of your suggestions but to no success. If I omit the user info the record will post correctly but, of course, without the needed user information. If I include the code the record won't insert at all but I receive no errors.
I should note the following. In my previous post I had a typo (CCSetSeesion should have read CCGetSession). That is not the problem. Also, my form has no reference at all to a user id. The source table does not contain a user_id field. Only the insert table does. I don't understand the usage of $db->f. Does it rely on my source table having user_id?
Thanks again!
_________________
Toshiba Satellite X205 laptop, Intel(R) Core(TM)2 Duo CPU T7300 @ 2GHz, 4gb ram, Windows Vista Ultimate 32-bit, Dual 200gb 7200rpm hard drives (no raid), NVidia GeForce 8700M GT
|
 |
 |
wkempees
|
| Posted: 11/12/2007, 5:10 PM |
|
1. You state if you ommit the CCGetUserID(), the INSERT is successful, are
you sure.
That would indicate to me the $db is actually connected to the database, but
I have no sourcecode to check that it does.
2. Set the DB to debugmode, like this:
$db->Debug=True;
$SQL = 'INSERT INTO store_orders (order_date, order_status_id, total,
user_id)
VALUES ('
. $db->ToSQL(date("Y-m-d"),ccsDate)
. ',1,'
. $db->ToSQL($OrderTotal,ccsFloat)
. CCGetUserID()
. ')' ;
$db->query($SQL);
Your form will now fail, but it will show the exact SQL being offered to
MySQL.
Post it here for all of us to see!
Walter
|
|
|
 |
dcox
Posts: 29
|
| Posted: 11/12/2007, 6:25 PM |
|
Bless you Walter!
I definitely need to learn more about debugging! I could see by the last number (51) that the last two fields were not being separated. A comma did the trick . ","
Debug: query = INSERT INTO store_orders (order_date, order_status_id, total, user_id) VALUES ('2007-11-12',1,51)
Debug: query = SELECT MAX(order_id) FROM store_orders
Debug: query = SELECT a.product_id as product_id, a.quantity as quantity, price FROM store_shopping_cart_items a, store_products b WHERE a.product_id=b.product_id AND shopping_cart_id = 4
Debug: query = DELETE FROM store_shopping_cart_items WHERE shopping_cart_id = 4
Thanks a million!
_________________
Toshiba Satellite X205 laptop, Intel(R) Core(TM)2 Duo CPU T7300 @ 2GHz, 4gb ram, Windows Vista Ultimate 32-bit, Dual 200gb 7200rpm hard drives (no raid), NVidia GeForce 8700M GT
|
 |
 |
wkempees
|
| Posted: 11/13/2007, 5:53 AM |
|
all happy!
|
|
|
 |
|