SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Update Array

  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update Array

    I'm trying to make it so when an admin types in a username they can upgrade their account to an admin. But when I do that it says that its been upgraded but in reality it isn't.

    Here is the code:

    Code:
    	function AddAdmin(){
    		
    		$this->view->url	=	$this->config->url;
    		$this->view->ID 	  = get_class($this);
    		$this->view->Title = "iOwn > Admin > Edit Admin";
    		
    		$add = isset($_POST['add_username']) ? $_POST['add_username'] : '';
    
    		$this->view->msg = "";
    		$this->view->err = false;
    
    		$sql = "SELECT * FROM users WHERE username = :username ";
    		$arr = array(":username" => $add);
    		$ctr = $this->database->DBCtr($sql,$arr);
    		$this->view->admin = $ctr[0]['admin'];
    
    		if($add == ""){
    			$this->view->msg = "You must enter a username";
    		}elseif($this->view->admin == 1){
    			$this->view->msg = "This user is already an Admin";
    		}elseif($ctr <= 0){
    			$this->view->msg = "Users is Not Found";
    		}else{
    			$arr = array(":admin" => 1);
    			$this->database->DBSet($arr,'users',$whr = 'WHERE username = '.$add);
    			$this->view->msg = "Admin Rights Added";
    			$this->view->err = true;
    		}
    		$this->view->render('Admin/AddAdmin');
    				
    	}
    I have also tried to put
    Code:
    $this->view->yes = 1;
    up above
    Code:
    $this->view->msg = "";
    and then instead of
    Code:
    $arr = array(":admin" => 1);
    I tried
    Code:
    $arr = array(":admin" => $this->view->yes);
    And it still says that the admin rights have been added but in reality they haven't been.

    Admin is a column in my database.

  2. #2
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    676
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    I've not worked with constructor functions so I may be way off, but that double = = sign in the $whr line just doesn't look right to me. Seems like you'd want to just define the WHERE and VALUES separate.
    PHP Code:
    $whr "WHERE username = :username";    
    $cnd = array(":username" => $add);
    $this->database->DBSet($arr,'users',$whr,$cnd); 
    Sure this would mean adding that extra argument to the function but it make more sense to me anyway. Hey, but this whole process looks a little foreign to me.


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
  •