I've spent hours over this code (i'm a php newbie) but I just can't figure out why it doesn't work. I have 2 webpages: the main one, and the login handler. The login one should take the values I put in the login form (placed in the main page) and then execute operations such as checking whether the user exists or not, whether he is an admin or not and whatsoever. Turns out the starting postgres query is wrong for some reasons -or maybe I should say the values taken from the form are not recognized correctly -, even though I tried to use it on another test.php page using actual values instead of the $_POST variables and it worked flawlessly
MainPage
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$host = "host=127.0.0.1";
$port = "port=5432";
$dbname = "dbname=Library";
$credentials = "user=john password=doe";
$db = pg_connect( "$host $port $dbname $credentials" ) or die('Could not connect');
?>
<title>Welcome</title>
<head><font size="16" color="black">Library</font></head>
<br />
<br />
<br />
<body>
<form action="LoginHandler.php" method="POST">
ID:<input type="string" name="UserID">
Password:<input type="string" name="Password">
<input type="submit" value="Login">
</form>
<form action="createUser.html" method="get">
<input type="submit" value="Sign Up"><br>
</body>
LoginHandler
<?php
$UserID=$_POST["UserID"];
$Password=$_POST["Password"];
$user=pg_query($db, "SELECT UserID, Password, Privileges
FROM Library.Users
WHERE UserID='$UserID' AND Password='$Password'");
$val = pg_fetch_result($user, 0, 0);
echo $val;
?>
I just tried the code on a text page again so I'm 100% sure the query is correct. Any suggestions?