|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
Thanks!! |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > PostgreSQL Help > PostgreSQL+Apache+PHP 4 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|