I am trying to get crypt passwords out of a database for a members log in. A person will type in their name and password and if it is recognized in the database table then it will let them in to other areas of the web section. I am new to crypt and having a little trouble getting it to work. When I run my code I get a notice that reads “Trying to get property of non-object”. I’m missing something but not sure what it is. My database table is set up like this:
Members table:
Name – primary key
Password
If someone can help me I appreciate it thanks.
r.
Here is my php code:
[php]
<?php
session_start();
if (isset($_POST['userid']) && isset($_POST['password']))
{
// if the user has just tried to log in
$userid = $_POST['userid'];
$password = $_POST['password'];
$db_conn = new mysqli('localhost', 'root', 'newpass', 'memdata');
if (mysqli_connect_errno()) {
echo 'Connection to database failed:'.mysqli_connect_error();
exit();
}
$query = 'select * from members '
."where name='$userid' "
." and password=crypt('$password')";
$result = $db_conn->query($query);
if ($result->num_rows >0 )
{
// if they are in the database register the user id
$_SESSION['valid_user'] = $userid;
}
$db_conn->close();
}
?>
[/php]