Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Alk
    Alk is offline
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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());


  • #3
    Alk
    Alk is offline
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •