#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Any help for me?


    Any help for me?

    Postby billys Sat Mar 16, 2013 10:15 pm
    I get the following error message when I try to run the code below ( Warning: Missing argument 6 for User::create_account(), called in /Applications/MAMP/htdocs/ghalive.com/register.php on line 64 and defined in /Applications/MAMP/htdocs/ghalive.com/includes/classes/user.class.php on line 165)

    registration.php
    if (DEMO_MODE == 'ON')
    {
    $message = "<div class='notification-box warning-notification-box'><p>Sorry, you can't do that while demo mode is enabled.</p><a href='#' class='notification-close warning-notification-close'>x</a></div><!--.notification-box .notification-box-warning end-->";
    }
    else
    {
    if ($username != "" && $email != "" && $password != "" && $repeat_password != "")
    {
    if($password == $repeat_password)
    {
    if(!$check_username)
    {
    if(!$check_email)
    {
    if (ALLOW_REGISTRATIONS == "NO")
    {
    if($invite)
    {
    // now that everything is ok, we can now register the user.
    $plain_password = $password;
    $password = md5($password);
    $user->create_account($username, $email, $password, $plain_password, $signup_ip, $invite_code);
    }
    else
    {
    $message = "<div class='notification-box warning-notification-box'><p>Sorry, but that invite code does not exist.</p><a href='#' class='notification-close warning-notification-close'>x</a></div><!--.notification-box .notification-box-warning end-->";
    }
    }
    else
    {
    // now that everything is ok, we can now register the user.
    $plain_password = $password;
    $password = md5($password);
    $user->create_account($username, $email, $password, $plain_password, $signup_ip);
    }
    }
    else
    {
    $message = "<div class='notification-box warning-notification-box'><p>Sorry, but that email address has already been taken.</p><a href='#' class='notification-close warning-notification-close'>x</a></div><!--.notification-box .notification-box-warning end-->";
    }
    }
    else
    {
    $message = "<div class='notification-box warning-notification-box'><p>Sorry, but that username has already been taken.</p><a href='#' class='notification-close warning-notification-close'>x</a></div><!--.notification-box .notification-box-warning end-->";
    }
    }
    else
    {
    $message = "<div class='notification-box warning-notification-box'><p>Passwords don't match.</p><a href='#' class='notification-close warning-notification-close'>x</a></div><!--.notification-box .notification-box-warning end-->";
    }
    }
    else
    {
    $message = "<div class='notification-box warning-notification-box'><p>Please complete all required fields.</p><a href='#' class='notification-close warning-notification-close'>x</a></div><!--.notification-box .notification-box-warning end-->";
    }
    }

    }
    else
    {
    // Form has not been submitted.
    $username = "";
    $email = "";
    $password = "";
    $repeat_password = "";
    $invite_code = "";
    }

    ?>




    create_account function:
    public function create_account($username, $email, $password, $plain_password, $signup_ip, $invite_code)
    {
    global $database;
    $session = new Session();

    // Generate the users ID.
    $user_id = generate_id();

    $sql = "SELECT * FROM ".self::$levels_table_name." WHERE auto = '1'";
    $query = $database->query($sql);
    $row = $database->fetch_array($query);
    $user_level = $row['level_id'];

    $flag = false;
    //until flag is false
    while ($flag == false)
    {
    //check if the user id exists
    $sql = "SELECT * FROM ".self::$table_name." WHERE user_id = '{$user_id}'";
    $query = $database->query($sql);
    $rows = $database->num_rows($query);
    //if it does try again till you find an id that does not exist
    if ($rows){
    $user_id = generate_id();
    }else{
    //if it does not exist, exit the loop
    $flag = true;
    }
    }
    if ($flag == true)
    {
    //insert into database the data
    $datetime = strftime("%Y-%m-%d %H:%M:%S", time());
    if(VERIFY_EMAIL == "NO"){$activated = 1;} else if(VERIFY_EMAIL == "YES"){$activated = 0;}

    $sql = "INSERT INTO ".self::$table_name." VALUES ('' '$username', '$email', '$password', '$user_level', '0', '', '$activated', '0', '$datetime', '', '0', '$signup_ip', '', '0', '', '', '')";
    $database->query($sql);

    if (ALLOW_REGISTRATIONS == "NO")
    {
    $sql = "DELETE FROM ".self::$invites_table_name." WHERE code = '{$invite_code}' ";
    $database->query($sql);
    }

    // Send and email to the user.
    if(VERIFY_EMAIL == "NO")
    {
    // Initialize functions.
    $email_class = new Email();

    // Email sent to the user if logged in.
    $from = SITE_EMAIL;
    $subject = "Welcome to ".SITE_NAME." ";

    $message = $email_class->email_template('registration_success', "$plain_password", "$username", "", "");
    $email_class->send_email($email, $from, $subject, $message);
    } else if(VERIFY_EMAIL == "YES") {
    //$activation_hash = Activation::set_activation_link($email)
    Activation::set_activation_link($plain_password, $email);
    }

    // Create the message that will be displayed on the login screen once the user has been redirected.
    $session->message("<div class='notification-box success-notification-box'><p>Your account has been created successfully. Please check your email for activation link.</p><a href='#' class='notification-close success-notification-close'>x</a></div><!--.notification-box .notification-box-success end-->");

    // redirect the user to the login page.
    redirect_to('login.php');
    }
    }
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    140
    According to your static method definition, create_user is supposed to take 6 parameters as arguments

    PHP Code:
    . . .
    public function 
    create_account
    (
        
    $username
        
    $email
        
    $password
        
    $plain_password
        
    $signup_ip
        
    $invite_code
    )
    {
    . . .
    }
    . . . 
    Now I did a copy/paste of the code you provided above in my text editor and I saw that at the line n 34 you provide 5 arguments instead of 6

    PHP Code:
    else
    {
    $user->create_account
    (
        
    $username
        
    $email
        
    $password
        
    $plain_password
        
    $signup_ip);


    Which obviously will be rejected by PHP as there is no default value for any of the function's parameters.


    Regards,
    Dariyoosh
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Thanks for the reply. Yeah I did, the point is when you are registering by an invitation, then the arguments are 6 but normal registration takes 5 arguments.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    140
    Originally Posted by billys
    Thanks for the reply. Yeah I did, the point is when you are registering by an invitation, then the arguments are 6 but normal registration takes 5 arguments.
    That's why I said, there are no default values for any of the function arguments. You need therefore to make some difference either by using default values in the function signature or by any other method between a person who has been registered by invitation and others.

    Here is an example:

    PHP Code:
    <?PHP
        
    class MyMathClass
        
    {
            public static function 
    sum($arg1$arg2)
            {
                return 
    $arg1 $arg2;
            }
        }

        echo 
    MyMathClass::sum(100);
    ?>
    This gives me the following error

    Code:
    Warning: Missing argument 2 for MyMathClass::sum(), called in /var/www/html/myscript.php on line 31 and defined in /var/www/html/myscript.php on line 25
    
    Notice: Undefined variable: arg2 in /var/www/html/myscript.php on line 27
    100
    But if I provide a default value

    PHP Code:
    <?PHP
        
    class MyMathClass
        
    {
            public static function 
    sum($arg1$arg2=200)
            {
                return 
    $arg1 $arg2;
            }
        }

        echo 
    MyMathClass::sum(100);
    ?>
    This will work and will print 300.

    Regards,
    Dariyoosh
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Hi Dariyoosh, thanks for your reply. What am trying to do is users can register by means of friends invitation or normal registration. If its friends invitation registration, the arguments becomes 6 including $invite_code but if its normal registration like user clicks on register link in the site and he or she did, the arguments becomes 5 without $invite_code. Am looking for a way that even though create_account function: originally accepts 6 arguments, it should also accept 5 when the user is registering without invitation.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    140
    Originally Posted by billys
    Am looking for a way that even though create_account function: originally accepts 6 arguments, it should also accept 5 when the user is registering without invitation.
    Then you can try something similar to this:

    PHP Code:
    <?php
        
    function create_account
        
    (
            
    $username
            
    $email
            
    $password
            
    $plain_password
            
    $signup_ip
            
    $invite_code=NULL
        
    )
        {
            
    $arguments func_get_args();
            
            
    /* * * * * * * * * * * * * * * * * * * * * *
                * So here you can do the necessary tasks
                * based on the fact that whether the user
                * is being invited or not
                * * * * * * * * * * * * * * * * * * * * * *
                */
            
    if (is_null($invite_code))
                echo 
    "Normal registration" "<br>";
            else
                echo 
    "Registration via a friend" "<br>";
                
            
    print_r($arguments);
            echo 
    "<br><br>";
        }
        
        
        
    create_account
        
    (
            
    $username="user1"
            
    $email="user1@gmail.com"
            
    $password="passwd1"
            
    $plain_password="passwd1",
            
    $signup_ip="10.0.0.10"
        
    );
        
        
    create_account
        
    (
            
    $username="user2"
            
    $email="user2@gmail.com"
            
    $password="passwd2"
            
    $plain_password="passwd2",
            
    $signup_ip="10.0.0.11",
            
    $invite_code="invite_code-00002"
        
    );
    ?>

    Regards,
    Dariyoosh
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    how can I make my DB class work


    I have a database connection class which I want to use on all my DB transactions in a project. I have instantiated it but when I run a query as show in the code, nothing works. Can someone please tell me what am doing wrong.

    PHP Code:
    <?php
            
    class DB {

                protected 
    $db_name 'database';
                protected 
    $db_user 'user';
                protected 
    $db_pass 'pass';
                protected 
    $db_host 'host';

                function 
    __construct($db_config) {
                    
    $this->db_name;
                    
    $this->db_host;
                    
    $this->db_user;
                    
    $this->db_pass;
                }

                
    /* Open a connection to the database */
                
    public function connect() {
                    
    $connection mysql_connect($this->db_host$this->db_user$this->db_pass);
                    if (!
    $connection)
                        return 
    false;
                    
    $database mysql_select_db($this->db_name);
                    if (!
    $database)
                        return 
    false;
                    return 
    $connection;
                }

            }

            function 
    __construct$db_config ) {

                
    $db = new DB($db_config);
                
    $conn $db->connect();

            }

            if(
    $_POST)
            {

                
    //get type of vote from client
                
    $user_vote_type trim($_POST["vote"]);

                
    //get unique content ID and sanitize it (cos we never know).
                
    $music_id filter_var(trim($_POST["music_id"]),FILTER_SANITIZE_STRINGFILTER_FLAG_STRIP_LOW FILTER_FLAG_STRIP_HIGH);

                
    //check if its an ajax request, exit if not
                
    if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
                    die();
                } 

                switch (
    $vote_type)
                {           

                    
    ##### User liked the content #########
                    
    case 'up'

                        
    //check if user has already voted, determined by unique content cookie
                        
    if (isset($_COOKIE["voted_".$id]))
                        {
                            
    header('HTTP/1.1 500 Already Voted!'); //cookie found, user has already voted
                            
    exit(); //exit script
                        
    }

                        
    //get like value from database using id
                        
    $result mysqli_query($conn,"SELECT likes FROM likes WHERE id='$id' LIMIT 1");
                        
    $get_total_rows mysqli_fetch_assoc($result);

                        if(
    $get_total_rows)
                        {
                            
    //found record, update vote_up the value
                            
    mysqli_query($conn,"UPDATE votes SET likes=likes+1 WHERE id='$id'");
                        }else{
                            
    //no record found, insert new record in db
                            
    mysqli_query($conn,"INSERT INTO votes (id, likes) value('$id', 1)");
                        }

                        
    setcookie("voted_".$id1time()+7200); // set cookie that expires in 2 hour "time()+7200".
                        
    echo ($get_total_rows["likes"]+1); //display total liked votes
                        
    break;

    ?>

IMN logo majestic logo threadwatch logo seochat tools logo