PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 6th, 2001, 02:49 PM
dube dube is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Johannesburg, South Africa
Posts: 6 dube User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #2  
Old July 6th, 2001, 03:20 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
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.

Reply With Quote
  #3  
Old July 6th, 2001, 05:56 PM
dube dube is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Johannesburg, South Africa
Posts: 6 dube User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
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!!

Reply With Quote
  #4  
Old July 7th, 2001, 03:24 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,300 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 3 h 12 m 27 sec
Reputation Power: 56
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > PostgreSQL+Apache+PHP 4


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT