Jump to content

[SOLVED] MAX() and increasing resulting number by 1


WhiskeyMike

Recommended Posts

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?

Link to comment
Share on other sites

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 ...

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.