
July 7th, 2001, 02:24 PM
|
|
Gödelian monster
|
|
Join Date: Jul 1999
Location: Central Florida, USA
|
|
|
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
}
}
|