Forum Moderators: coopster
$sql = "SELECT * FROM login WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
$X = mysql_fetch_array($result);
$num = mysql_numrows( $result );
if ( $num!= 0 ) {
$auth = true;
}
}
if (! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
$school = "$X[school]";
$S1 = "SELECT * FROM jobs WHERE school = '$school'";
$S2 = mysql_query($S1);
while($S3 = mysql_fetch_array($S2))
{
print("$S3[title] : $S3[school]");
}
The problem I think is with the WHERE statement because when I take that out, I get all 10 entries from the jobs table printing the title field and the school field like it should. But with the above WHERE statement where I'm trying to limit it to one school only (according to the u and p submitted), I get just a blank page.
Basically, this is an attempt at session management using 2 MySQL tables so when the schoolA logs in (using the login table), they'll only see their records from another table I'm trying to associate with the login table.
it should be
$num = mysql_num_rows($result);
$school = $X["school"];
print($S3["title"]." : ".$S3["school"]);
In your code had $school = "$X[school]"; and let's say that the school was OUP, then
$school = "$X[school]";//this is the output: $school = array[school]
$school = $X["school"];//this is the output: $school = OUP
so you see the difference. "" means that it's a string, however simple variables are parsed there. On the other hand arrays and objects aren't being parsed.
Hope this helps
Michal Cibor