php - How to put the values of a array pulled from mySQL into variables -


i have been able query data mysql database , put array variable $results, not able put part of array, password or regtime in $results varible separate variables. doing wrong?

this select function in databse class querying data database using perameter of $query. works posts page, dont think problem.

// select function                    public function select($query){              $result = $this->connection->query($query);                            while ( $obj = $result->fetch_object()){                  $results[] = $obj;              }                            return $results;          }

this login function in query class putting submitted username query , passing select function above pull results username, returned login function , stored in $results variable. checks whether variable empty , if kills script, working get: 1)yay!!!! 2)and displayed print_r() is:

array ( [0] => stdclass object ( [id] => 1 [username] => dillon [fname] => dillon [lname] => erhardt [email] => dillon@erhardt.co.uk [password] => dilandsas [regtime] => 1453685794 ) )  

function login($redirect) {  			global $db;                            if(!empty($_post)) {                                    $username = htmlspecialchars($_post['username']);                  $password = htmlspecialchars($_post['password']);                                    $query = "                        select * users                        username = '$username'                      ";                                $results = $db->select($query);      				//kill script if submitted username doesn't exit  				if (empty($results)) {  					die('sorry, username not exist!');  				}                                     echo "yay";                  print_r($results);      				//the registration date of stored matching user  				$storeg = $results['regtime'];    				//the hashed password of stored matching user  				$stopass = $results['password'];

the problem when try , store vaule password or regtime results in $storeg , $stopass variables using $results['password']; or $results['regtime']; these notices

notice: undefined index: regtime in /applications/mamp/htdocs/test/cms-v2/includes/class-query.php on line 55  notice: undefined index: password in /applications/mamp/htdocs/test/cms-v2/includes/class-query.php on line 58 invalid login 

how store password , regtime values of array $results variable?

in select, fetch objects result set , add array (result).

accordingly, need grab object result array , reference property within that:

$storeg = $results[0]->regtime; 

this work, if $result contains 1 , 1 row db. other cases (no row, 3 rows) cause errors due missing error handling.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -