...

View Full Version : Member Registration ID Increment



Alk
03-01-2007, 12:13 AM
Hi
I am trying to setup a seperate member registration form for IPB 1.3. Unfortunately, IPB's table structure of mysql doesn't increment the member ID automatically. So, in their registration form, they increment it manually. This is what they have:

$DB->query("SELECT MAX(id) as new_id FROM ibf_members");
$r = $DB->fetch_row();

$member_id = $r['new_id'] + 1;

$member = array(
'id' => $member_id,
'name' => $in_username,
'password' => $in_password,
'email' => $in_email,
'mgroup' => $mem_group,
'posts' => 0,
'avatar' => 'noavatar',
'joined' => time(),
'ip_address' => $ibforums->input['IP_ADDRESS'],
'time_offset' => $ibforums->vars['time_offset'],
'allow_admin_mails' => 1,
'view_sigs' => 1,
'email_pm' => 1,
'view_img' => 1,
'view_avs' => 1,
'restrict_post' => 0,
'view_pop' => 1,
'vdirs' => "in:Inbox|sent:Sent Items",
'msg_total' => 0,
'new_msg' => 0,
'coppa_user' => $coppa,
'language' => $ibforums->vars['default_language'],
);
When I try to put it into my form I get the error "Call to a member function on a non-object" on line 19.
Here is what I have for my form:

<?php

// Include the Mysql Config file (config.php)
include '../config.php';

// Connect to Mysql
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

//Fetch data submitted from index.php form
$tableprefix = $_POST['tableprefix'];

//+--------------------------------------------
//| Find the highest member id, and increment it
//| auto_increment not used for guest id 0 val.
//+--------------------------------------------

$query = "SELECT MAX(id) as new_id FROM `".$tableprefix."_members`";
$r = $query->fetch_row();

$member_id = $r['new_id'] + 1;

// Insert into Mysql Database:
$query = "INSERT INTO `".$tableprefix."_members` (*query here-whatever it may be*)";
mysql_query($query) or die("Query failed: " . mysql_error());

// Show alert when data inserted to Mysql
echo "<script language=javascript>alert('*popup box message here-whatever it may be*'); window.location = '../index.html'; </script>";

// Close connection to Mysql
mysql_close($conn);
?>
It seems to be the row:

$r = $query->fetch_row();
..and the $r causing the error. I cannot find what $r is in the IPB registration handler. So I am wondering if there is a way to work around it?
I am new to PHP so don't understand a lot.:( I hope you have all the info needed. I am battling to get the member_id auto-incremented.
Thanks!:thumbsup:

Fumigator
03-01-2007, 01:12 AM
You have copied and pasted IPB's code improperly. Let me break it down for you:

They have $DB->query(blahblah). What this is saying is, call function "query" which is part of the $DB object, and the $DB object is a class created in another part of the code. This is all object-oriented programming.

You have copied that code, but you aren't creating any objects-- you are using PHP in the structured programming style. So your code $r = $query->fetch_row() is actually attempting to call a function inside object $r (which doesn't exist as an object), with a function name of the value of $query, which of course isn't what you intended to do at all.

Fixing it will be pretty easy, fortunately. Just do away with the OOP stuff (the ->) and do a little reading on how to do a "raw" query (by raw I mean without the OOP wrapped around everything).

Here's how I would fix your problem (might not be exactly what you need):


$query = "SELECT MAX(id) as new_id FROM `".$tableprefix."_members`";
$r = mysql_fetch_array($query);
if (!$r) {
die("query error occured! query = $query and error text is ".mysql_error());
}

Alk
03-01-2007, 01:42 AM
OK, thanks for your reply and explanation:thumbsup: . I put in:

$query = "SELECT MAX(id) as new_id FROM `".$tableprefix."_members`";
$r = mysql_fetch_array($query);
if (!$r) {
die("query error occured! query = $query and error text is ". mysql_error());
}

$member_id = $r['new_id'] + 1;

Unfortunately it comes out with the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in blahblahblah on line 19
query error occured! query = SELECT MAX(id) as new_id FROM `blah_members` and error text is
Then it is blank.
Any ideas? Before I implemented this part of the code I simply put in a fixed member ID in the mysql query and it worked without error. I don't think it is a problem with connecting to the database. The query works on it's own when I input it manually using a query tool.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum