0

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

Edited by kevinyu: added details

2
Contributors
4
Replies
32
Views
4 Years
Discussion Span
Last Post by kevinyu
0

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

1

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.