Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-28-2007, 11:13 PM   PM User | #1
Alk
New to the CF scene

 
Join Date: Jun 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Alk is an unknown quantity at this point
Member Registration ID Increment

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:
PHP Code:
        $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 Code:
<?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:
PHP Code:
$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!
Alk is offline   Reply With Quote
Old 03-01-2007, 12:12 AM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,687
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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):
PHP Code:
$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());

__________________
Fumigator is offline   Reply With Quote
Old 03-01-2007, 12:42 AM   PM User | #3
Alk
New to the CF scene

 
Join Date: Jun 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Alk is an unknown quantity at this point
OK, thanks for your reply and explanation . I put in:
PHP Code:
$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:
Quote:
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.
Alk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:11 AM.


Advertisement
Log in to turn off these ads.