I have posted code for my index() action from TestsController. To tell you what it does is that I login my username and password on that action. Since if you're only going to input the username and password, they are the only data that can go through $this->request->data. Now I will provide a sample table for reference.

CREATE TABLE Persons
(
uid int NOT NULL AUTO_INCREMENT,
username varchar(50),
password varchar(50),
fullname varchar(100),
age int(3),
PRIMARY KEY (uid)
);




public function index()
{
if($this->request->is('post'))
{
if(!$this->Test->findByUsernameAndPassword($this->request->data('Test.username'), $this->request->data('Test.password')))
{

$this->Session->setFlash("bad");
}

else
{

$mysqli = new mysqli("localhost","root", "", "test");


$query = "SELECT * FROM tests WHERE username='jimmorrison'";
$result = $mysqli->query($query);



$row = $result->fetch_array(MYSQLI_ASSOC);

$this->Session->setFlash($row['uid']); //display the corresponding age using setFlash
//$this->Session->setFlash($this->request->data('Test.age')); (this code does not work)

$result->close();
}
}
}

as you can see this is not how it's coded on CakePHP. But I would like to ask some feedbacks on how I am going to do this on Cake? I am using version 2.3.9

Haven't because I can't still fully understand the 1st parameter, which is 'first'. Would you mind explaining it to me ? :)

It means "return only the first row of the result set", it's like using limit 1 in a query. If you open the link that I pasted above, you can access the documentation of this method.

Thank you sir! I really haven't found the time to read the docs. I've been so busy these past few days.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.