SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Last prepare statement not working

    I have the following code that I am using to update two different tables in my database:

    PHP Code:
        public function Set_add_user($first_name$last_name$email$username$password_check$permissions) {
        
            global 
    $mysqli;
            
            
    $user_id '';
            
            if (
    $stmt $mysqli->prepare("INSERT INTO users (first_name, last_name, email, username, password) VALUES (?,?,?,?,?)")) {
                
    $stmt->bind_param("sssss"$first_name$last_name$email$username$password_check);
                if (
    $stmt->execute()) {
                    
    $this->users 'Success';
                } else {
                    
    $this->users 'Failed at INSERT 1';
                }
                
    $stmt->close();
            }
            
            if (
    $stmt $mysqli->prepare("SELECT user_id FROM users WHERE first_name = ? AND last_name = ? AND username = ?")) {
                
    $stmt->bind_param("sss"$first_name$last_name$username);
                
    $stmt->execute();
                
    $stmt->bind_result($user_id);
                
    $stmt->fetch();
                
    $this->users $user_id;
                
    $stmt->close();
            }
            
            if (
    $stmt $mysqli->prepare("UPDATE users SET permissions_id = ? WHERE user_id = ?")) {
                
    $stmt->bind_param("ii"$user_id$user_id);
                if (
    $stmt->execute()) {
                    
    $this->users 'Success';
                } else {
                    
    $this->users 'Failed at UPDATE 1';
                }
                
    $stmt->close();
            }
            
            
    $per_columns $per_values = array();
            foreach (
    $permissions as $key => $value) {
                
    $per_columns[] = $key;
                
    $per_values[] = 1;
            }
            
    $permissions_columns implode(', ',$per_columns);
            
    $permissions_values implode(', ',$per_values);
            
            if (
    $stmt $mysqli->prepare("INSERT INTO permissions (user_id, ?) VALUES (?, ?)")) {
                
    $stmt->bind_param("sis"$permissions_columns$user_id$permissions_values);
                if (
    $stmt->execute()) {
                    
    $this->users 'Success';
                } else {
                    
    $this->users 'Failed at INSERT 2';
                }
                
    $stmt->close();
            }
            
            return 
    $this->users;
            
        } 
    Everything works fine until I get down to the last prepare statement ("INSERT INTO permissions"...). I printed out the query by itself to make sure that it formats correctly, which gives me...

    PHP Code:
    INSERT INTO permissions (user_idper_usersper_organizationVALUES (7,1,1
    My database is set up so that user_id is an INT and per_users and per_organization are also INT's.

    Am I writing this out incorrectly? Any help would be much appreciated. It isn't shooting me an error message, it is simply not adding the permissions into the database.
    James Web Development | New York, NY
    Design, Develop, Deliver

  2. #2
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind! I made a stupid mistake! There is another column in my table that is NOT NULL that I wasn't adding in as well. Sorry to take up space!
    James Web Development | New York, NY
    Design, Develop, Deliver


Bookmarks

Posting Permissions

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