Kryptix Posted May 8, 2010 Share Posted May 8, 2010 It's a clan system for this game I run. First of all I insert a new record into `clans` and then grab the mysql_insert_id() so I can update their user record with what clan they're in. The first query works fine, but the only bit that works on the second query is setting `clan_since` to UNIX_TIMESTAMP(). Setting `clan` to mysql_insert_id() doesn't work and neither does setting `clan_confirmed` to '1'. I echo()'d out the exact query too and it looks fine: UPDATE `users` SET `clan` = '15', `clan_confirmed` = '1', `clan_since` = UNIX_TIMESTAMP() WHERE `id` = '101' When I copy and paste that into phpMyAdmin it works absolutely fine... So seriously, what's wrong? It's probably going to be something simple but I've been trying to fix this for 3 hours now and my mind feels like it's gunna explode. $db->query("INSERT INTO `clans` (`owner`, `tag`, `name`, `created_time`, `created_ip`, `created_user`) VALUES ('" . $db->escape($pun_user['id']) . "', '" . $db->escape($_POST['tag']) . "', '" . $db->escape($_POST['clan']) . "', UNIX_TIMESTAMP(), '" . $db->escape($_SERVER['REMOTE_ADDR']) . "', '" . $db->escape($pun_user['id']) . "')"); $id = $db->insert_id(); $db->query("UPDATE `users` SET `clan` = '" . $db->escape($id) . "', `clan_confirmed` = '1', `clan_since` = UNIX_TIMESTAMP() WHERE `id` = '" . $db->escape($pun_user['id']) . "'"); echo "UPDATE `users` SET `clan` = '" . $db->escape($id) . "', `clan_confirmed` = '1', `clan_since` = UNIX_TIMESTAMP() WHERE `id` = '" . $db->escape($pun_user['id']) . "'"; Quote Link to comment https://forums.phpfreaks.com/topic/201077-been-looking-at-this-for-far-too-long-now/ Share on other sites More sharing options...
Sulman Posted May 8, 2010 Share Posted May 8, 2010 It looks ok. The problem is most likely in you db class: <?php $id = $db->insert_id(); ?> It looks like the insert_id method is not returning the correct data. If you echo out $id what do you get? Can you post the insert_id code. Quote Link to comment https://forums.phpfreaks.com/topic/201077-been-looking-at-this-for-far-too-long-now/#findComment-1054961 Share on other sites More sharing options...
Kryptix Posted May 8, 2010 Author Share Posted May 8, 2010 I showed in my first post that I echo()'d out the query and I copied and pasted it too. It isn't just that which isn't setting, `clan_confirmed` isn't being set to 1 either. I've used $db->insert_id() in another page and it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/201077-been-looking-at-this-for-far-too-long-now/#findComment-1054962 Share on other sites More sharing options...
harristweed Posted May 8, 2010 Share Posted May 8, 2010 Sometimes the 'slanted apostrophe' will cause problems, try replacing with apostrophes from the keyboard Quote Link to comment https://forums.phpfreaks.com/topic/201077-been-looking-at-this-for-far-too-long-now/#findComment-1054964 Share on other sites More sharing options...
Kryptix Posted May 8, 2010 Author Share Posted May 8, 2010 Ugh. Never mind. I had another query at the bottom of the page updating it back to normal... Blah! I originally put it there as a debug and forgot to remove it. Cheers anyway. Quote Link to comment https://forums.phpfreaks.com/topic/201077-been-looking-at-this-for-far-too-long-now/#findComment-1054968 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.