# Pulling crypt passwords from MySQL

**URL:** <https://www.phphelp.com/t/pulling-crypt-passwords-from-mysql/24199>\
**Category:** General Database (Oracle, SQL Server, etc)\
**Created:** [April 17, 2015, 5:53pm UTC](https://www.phphelp.com/t/pulling-crypt-passwords-from-mysql/24199 "2015-04-17T17:53:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![r-man](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@r-man](https://www.phphelp.com/u/r-man)\
**Post date:** [April 17, 2015, 5:53pm UTC](https://www.phphelp.com/t/pulling-crypt-passwords-from-mysql/24199/1 "2015-04-17T17:53:12Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![grwebugy](https://www.phphelp.com/user_avatar/www.phphelp.com/grwebugy/32/1076_2.png) [@grwebugy](https://www.phphelp.com/u/grwebugy)\
**Post date:** [April 23, 2015, 11:20pm UTC](https://www.phphelp.com/t/pulling-crypt-passwords-from-mysql/24199/2 "2015-04-23T23:20:33Z")

</div>

getting property of a non object means that whatever you are try to get, the value is not an object. Could be an array, could be not there.

You didn’t say at what point you were getting this message.

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [April 25, 2015, 1:52am UTC](https://www.phphelp.com/t/pulling-crypt-passwords-from-mysql/24199/3 "2015-04-25T01:52:48Z")

</div>

For starters, you may want to use this version of the password,

[php] $password = crypt($\_POST[‘password’]);[/php]  
You should also be using prepared statements.

You may also want to wrap the database connection stuff in a try catch. If there are problems, you will probably want to do something about it.
