PDA

View Full Version : Can you spot the code error here ???


mistyPotato
11-28-2007, 10:23 AM
Can someone tell me why I'm getting the ERROR below with this code ?


$db->query_write("
INSERT INTO " . TABLE_PREFIX . "logins
(UserName, UserID, LoginDate)
VALUES
(" . $vbulletin->userinfo['username'] . ", " . $vbulletin->userinfo['userid'] . ", " . (!empty($post['moderateddateline']) ? $post['moderateddateline'] : TIMENOW) . ")
");




Database error in vBulletin 3.6.4:

Invalid SQL:

INSERT INTO forumlogins
(UserName, UserID, LoginDate)
VALUES
(MotoGal, 1, 1196252440);

MySQL Error : Unknown column 'MotoGal' in 'field list'
Error Number : 1054


Thanks !

--------------- Added 1196254482 at 1196254482 ---------------

For anyone who encounters this problem....

I changed the Query string as follows and now it works....



$db->query_write("
INSERT INTO " . TABLE_PREFIX . "logins
(UserName, UserID, LoginDate)
VALUES
('" . $db->escape_string($vbulletin->userinfo['username']) . "', " . $vbulletin->userinfo['userid'] . ", " . (!empty($post['moderateddateline']) ? $post['moderateddateline'] : TIMENOW) . ")
");

Opserty
11-28-2007, 10:55 AM
You need to place strings in single quotes.


$db->query_write("
INSERT INTO " . TABLE_PREFIX . "logins
(UserName, UserID, LoginDate)
VALUES
('" . $vbulletin->userinfo['username'] . "', " . $vbulletin->userinfo['userid'] . ", " . (!empty($post['moderateddateline']) ? $post['moderateddateline'] : TIMENOW) . ")
");