atl_andy Posted March 24, 2008 Share Posted March 24, 2008 I have a login script that I modified from MySQL to work in Postgres. There is one part that I don't think was translated properly. The problem area is listed in the comments in the code. Any help is greatly appreciated. <?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 = pg_connect('dbname=secret user=secret password=secret'); $query = "SELECT * FROM authorized_users WHERE name='$userid' AND password='$password' "; $result = pg_query($query); if ($result->num_rows >0) /*This is the area of difficulty. I have tried different compares, but nothing is working. Any ideas? It doesn't work with the current compare. It will log everyone in if it is changed, say, to ($result >0) or something. */ { // if they are in the database register the user id $_SESSION['valid_user'] = $userid; } pg_close($db_conn); } if (isset($_SESSION['valid_user'])) { main page....cool functionality } else { if (isset($userid)) { echo 'Could not log you in.<br />'; } else { echo 'You are not logged in.<br />'; } Log in form goes here...... } >? Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 24, 2008 Share Posted March 24, 2008 Because you are using pg_query, it simply is returning a resource, so you need to do a comparison like this: <?php if (pg_num_rows($result) > 0) { // Records returned } ?> Quote Link to comment Share on other sites More sharing options...
atl_andy Posted March 24, 2008 Author Share Posted March 24, 2008 That worked, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.