#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Johannesburg, South Africa
    Posts
    6
    Rep Power
    0

    Angry PostgreSQL+Apache+PHP 4


    I have installed PHP 4.0.5 + PostgreSQL 7.1.2+ Apache 1.3.20 and Linux RedHat 7.1.
    Two problems:
    (1) I have stored a name "Joe" and a password "Blow" in a database....

    CREATE TABLE students(name char(10), pass char(10));
    INSERT INTO students values ('Joe','Blow');
    ......

    When I login as "Joe" and password "Blow" on a form My script fetches them from the database successfully.
    (I checked with ---- echo name; echo pass;
    But when I do :

    if((name==$name) &&(pass==$password)){echo "Hello J.B."}
    else echo "Who the @#$% are you?";

    it always prints "Who the @#$% are you?" instead of
    "Hello J.B."


    Can anybody tell me why it seems "joe" "blow" from the database
    and "joe" "blow" supplied through a log in form are not "equal"?

    2.I have trouble with the following:

    $db = pg_connect("dbname=students user=postsgres")||die("I got a head ache!!");

    The connection is successful.
    But then the following lines

    $query="SELECT * FROM students";
    $result=pg_exec($db, $query);
    ........

    I get an error for the last line: "....is not a valid PostgreSQL resource link".

    As far as I can determine there is nothing wrong with the code!

    Please help, I am an absolute newbie to PHP+PostgreSQL+Apache
    Last edited by dube; July 6th, 2001 at 05:54 PM.
  2. #2
  3. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    30
    Problem 1: Should your (pass=$password) have two equal signs?

    Problem 2: I don't know. I could only find one link to a problem like yours but it was a dead one so I couldn't get any info.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Johannesburg, South Africa
    Posts
    6
    Rep Power
    0
    Originally posted by dcaillouet
    Problem 1: Should your (pass=$password) have two equal signs?


    Yes!!! I am comparing two strings

    Problem 2: I don't know. I could only find one link to a problem like yours but it was a dead one so I couldn't get any info.

    Thanks!!
  6. #4
  7. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    I'm still trying to understand exactly how you've structured your page, but

    if((name==$name) &&(pass==$password)){echo "Hello J.B."}
    else echo "Who the @#$% are you?";

    is not a syntactically or structurally meaningful piece of code. You've got the word "name", there, with no quotes, so I assume it's not meant to be a string, but you don't have it identified as a variable either. (unless you have somewhere declared it to be a global). Also, your approach would only work with one record in the database; what would you do with multiple students and passwords?

    Let's just say that the form where you log in has the text fields
    <input type="text" name="name">
    <input type="password" name="password">

    Now, when you submit this and go to your form handler, you have two variables: $name and $password. Now let's say you query your database:

    $db = pg_connect("dbname=students user=postsgres") or die(pg_errormessage());

    //I'm assuming you have a database named "students" and a table in that database named "students"
    //now you have two ways to go here
    //1) You don't even need to actually extract the values from the database, just use a
    // WHERE query to see if the values are in there. Much more efficient:

    $result=pg_exec($db, "SELECT * from students WHERE name='$name' AND password='$password'");

    if(pg_numrows($result) == 0) {
    echo "No match";
    }

    elseif(pg_numrows($result) == 1) {
    echo "We got a match";
    }

    elseif(pg_numrows($result) > 1) {
    echo "We got a problem; there shouldn't be more than one.";
    }

    //or choice 2:
    $result=pg_exec($db, "SELECT * from students");
    while($rows = pq_fetch_array($result)){

    if(($row["name"] == $name) && ($row["password"] == $password)){
    echo "We found it"; // But if accidentally there are more than one, we have
    //no way to check, without more PHP array manipulation
    }

    }
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com

IMN logo majestic logo threadwatch logo seochat tools logo