Why is my login not setting a cookie/working?

Started by Jade Elizabeth, October 09, 2014, 03:12:03 AM

Previous topic - Next topic

Jade Elizabeth

My login code is...

<?php
global $db;
require (
root '/model/connect.php');

$password $_POST['admin_password'];
$username $_POST['admin_login'];

$query "SELECT * FROM admin_user WHERE admin_login='$username' and admin_password='$password'";
$result $db->query($query);


// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
// Set cookies. I set my cookies to last 24 hours
$expires 1000 60 60 24;
setcookie("username"$usernametime()+$expires);
setcookie("password"$passwordtime()+$expires);
setcookie("admin""1"time()+$expires);
}
else 
{
// No matching user
$error "No matching username/password";
}
?>


My connection thing is:
<?php
// Connection credentials
$dsn 'mysql:host=localhost;dbname=universities_db';
    
$username 'root';
    
$password '';

// Connect
    
try
{
$db = new PDO($dsn$username$password);
    
}

// Errors?
catch (PDOException $e)
{
$error_message $e->getMessage();
include('errors/database_error.php');
exit();
    
}



No matter what I do $_COOKIE['admin'] is not being set and it's driving me crazy. I've got the right username and pass and it's in the db. When I test the query it gives me one result.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Oldiesmann

Already mentioned this to you on messenger but I'll post it here as well in case anyone's curious...

The problem is you can't use mysql_num_rows on the results of $db->query since PDO::query returns a PDOStatement object, not a MySQL result resource. You need to use $result->rowCount() instead.
Michael Eshom
Christian Metal Fans

Jade Elizabeth

Thank you SO SO MUCH Oldies!!!!! :D :D :D

I'm so new to all this and he throws PDO at us and forces us to use it, I don't even know what it is :S.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Advertisement: