$select=$pdo->prepare(" SELECT * FROM users WHERE username=’".$username."’ AND password=’".$password."’ LIMIT 1 ");
$select->execute();
$linha=$select->fetchAll(PDO::FETCH_ASSOC);
foreach($linha as $row ){
If I would knew PDO, I would truly help you, however I don’t know. As far as I know, PDO is better at returning different results, however I would use mysqli_* instead, which is far more simple and has future support as well:
$connection = mysqli_connect("localhost", "username", "password", "database"); // connect and select DB at the same time
$sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1 ";
$res = mysqli_query($connection, $sql) or die(mysqli_error($connection));
if (mysqli_num_rows($res) > 0)
{
$rows = mysqli_fetch_all($res); // converts object $res into array $rows; $rows is multi-dimensional in this case
print_r($rows); // prints the entire $rows array
print("<br><br>");
foreach($rows as $row => $cols) // walk through array
{
foreach($cols as $col => $val) // walk through array
{
print($val . "<br>"); // output value of each col
}
}
}
else
{
print("No rows returned.");
}
Or better…
$connection = mysqli_connect("localhost", "username", "password", "database"); // connect and select DB at the same time
$sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1 ";
$res = mysqli_query($connection, $sql) or die(mysqli_error($connection));
if (mysqli_num_rows($res) > 0)
{
$row = mysqli_fetch_row($res); // converts object $res into array $rows;
foreach($row as $col => $val)
{
print($val . "<br>");
}
}
else
{
print("No row returned.");
}