Fwd: Query results - Mailing list pgsql-novice

From Trevor Morrison
Subject Fwd: Query results
Date
Msg-id 02031822094400.16405@stud
Whole thread Raw
Responses Re: Fwd: Query results
Re: Fwd: Query results
List pgsql-novice
Hi,

I am trying to setup a simple databaes authoriztion of users using
Postgresql 7.2 and PHP 4.1.  I have
included the code below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<!--Call this file login2.php-->
<!--This file begins like any other file-->

<html>

<head>
<title>My Login Form</title>
</head>
<body>
<?php
switch($do) {

    case "authenticate":

    $Host = "localhost";
    $User = "trevor";
    $Password = "";
    $DBName = "users";
    $TableName="users";

    $Link = pg_connect("host=$Host dbname=$DBName user=$User") or die ("Couldn't
connect to the database");

    $Query = "SELECT  id from $TableName where username='$username' and
password='$password'";

    $results = pg_exec($Link, $Query) or die ("Couldn't connect to the
database");

    $num = pg_numrows($results) or die ("Couldn't count rows");

    if ($num == 1) {

    echo "<P>You are a valid user!<BR>";
    echo "Your user name is $username<BR>";
    echo "Your user password is $password</P>";

    }
        else if ($num == 0){
            unset ($do);
            echo "<P>You are not authorized! Please try again.</p>";
            include("login_form.inc");
    }
    break;

    default:
    include("login_form.inc");
}

?>
</body>
</html>


This script works great as long as the name is in the database, but if it is
not then $num has no value and conseqently errors out.  Even if you use the
correct firstname and and an incorrect password the pg_numrows errors out.

Any help would be appreciated.

Trevor

-------------------------------------------------------

-------------------------------------------------------

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Estimating Database Disk Space
Next
From: Bai Yan
Date:
Subject: rename a table name