Jump to content

PHP Login Script Help - Postgres/PHP


atl_andy

Recommended Posts

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......
    }
>?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.