WhiskeyMike Posted February 1, 2008 Share Posted February 1, 2008 I have a form where I can go and review applications. When I activate an application, I INSERT the information into two databases. The second database I'm trying to INSERT information into is a phpbb forum user table. I need to find the maximum number of the user_id column and increase that by one. Here is my code: $db = mysql_connect($fdbhost, $fdbuname, $fdbpass) or die("Could not connect to the SQL server<br>"); mysql_select_db($fdbname); $query = "SELECT MAX(user_id) FROM phpbb_users"; $result = mysql_query($query); if ( !$result ) die("Query for Orders in table ORDERS failed.<br>"); $newId = ++$query; $db = mysql_connect($fdbhost, $fdbuname, $fdbpass) or die("Could not connect to the SQL server<br>"); mysql_select_db($fdbname); $query = "INSERT INTO phpbb_users (user_id,user_active,username,user_password,user_session_time,user_level,user_posts,user_timezone,user_style,user_new_privmsg,user_unread_privmsg,user_viewemail,user_allowhtml,user_allow_pm,user_allow_viewonline,user_notify_pm,user_popup_pm,user_email) VALUES ("; $query .= "'".$newId."',"; // USER ID $query .= "1,"; // ACTIVE $query .= "'".$pilotid."',"; // USERNAME $query .= "'".$outpass."',"; // PASSWORD $query .= "1201885515,"; // USER SESSION TIME $query .= "0,"; // USER LEVEL $query .= "0,"; // USER POSTS $query .= "-6.00,"; // USER TIME ZONE $query .= "1,"; // USER STYLE $query .= "0,"; // USER NEW PRIVMSG $query .= "0,"; // USER UNREAD PRIVMSG $query .= "1,"; // USER VIEW EMAIL $query .= "1,"; // USER ALLOW HTML $query .= "1,"; // USER ALLOW PM $query .= "1,"; // USER ALLOW VIEW ONLINE $query .= "1,"; // USER NOTIFY PM $query .= "1,"; // USER POPUP PM $query .= "'".$email."'"; // USER EMAIL $query .= ")"; $result = mysql_query($query); But when I check the new user in the table, it shows the user_id value as 0... not increasing it from the previous maximum user_id. Any ideas on what I'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/88951-solved-max-and-increasing-resulting-number-by-1/ Share on other sites More sharing options...
nickdrums Posted February 1, 2008 Share Posted February 1, 2008 Looks like you are not actually reading the data row properly. You need something like: $query = "SELECT max_user as MAX(user_id) FROM phpbb_users"; $result = mysql_query($query); if ( !$result ) die("Query for Orders in table ORDERS failed.<br>"); $row = mysql_fetch_array($result); $newId = $row['max_user'] + 1; Hope this helps ... Quote Link to comment https://forums.phpfreaks.com/topic/88951-solved-max-and-increasing-resulting-number-by-1/#findComment-455588 Share on other sites More sharing options...
WhiskeyMike Posted February 1, 2008 Author Share Posted February 1, 2008 Looks like you are not actually reading the data row properly. You need something like: $query = "SELECT max_user as MAX(user_id) FROM phpbb_users"; $result = mysql_query($query); if ( !$result ) die("Query for Orders in table ORDERS failed.<br>"); $row = mysql_fetch_array($result); $newId = $row['max_user'] + 1; Thanks nickdrums.... it worked, with the exception of one thing. Where you had: $query = "SELECT max_user as MAX(user_id) FROM phpbb_users"; I had to change to: $query = "SELECT MAX(user_id) as max_user FROM phpbb_users"; Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/88951-solved-max-and-increasing-resulting-number-by-1/#findComment-455592 Share on other sites More sharing options...
nickdrums Posted February 4, 2008 Share Posted February 4, 2008 Ah sorry - my imperfect memory of MySQL syntax! All well, glad it got you moving ... Nick. Quote Link to comment https://forums.phpfreaks.com/topic/88951-solved-max-and-increasing-resulting-number-by-1/#findComment-458018 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.