Problems with script that logs in to a database with a pass



I am new in PHP
I have made a script that will log in to a database with a password and a username
I am writing the user name and the password and it’s not log in.
I don’t know what I am doing wrong !!!!!
Thank You
I have put the script on my webpage because probably is to big to post it on this Forum
I did some test and the script connects to the Database.
Probably something is wrong on the part of the script that checks the username and password
I don’t get any error. That the script is not working.

Please Help
$result = mysql_query($query, $connection);

try using:

$result = mysql_query($query) or die(mysql_error());
I tried to do this change that you told but nothing happened

I have tried to do the same thing but I am using now tow php pages.
In to the first file I have the form that the user fills the username and the password.
And then I have the second php page that checks in to the database if the username and the password is correct.
I run the form I enter the user name and the password and then in the psscript.php I have this error message:

Parse error: syntax error, unexpected $end in c:\diphp\webroot\pscript.php on line 52
What am I doing wrong ?

In the previous script I was trying to have in a one page the form script and the verifying script?
If you have any idea please tell me ???
Thank you

Go to this page to see the new script:
Also use:

if(isset($_SESSION['valid_user'])) { }

Instead of:

# This one is deprecated
if(session_is_registered("valid_user")) {}

I replace that line that you told me and I also I had tow open braces on an IF.

Now the script it not showing any error but I can’t log in with the password and the user name. The script stops to the first if and it echo out “You have not entered all the required details”

if (!$first_name || !$last_name)
	echo "You have not entered all the required details . <br>";

Is the form script ok because it seem that is not passing the values to the verifying script????
Thank You!
	<title> PASS </title>
<h1>Home page</h1>
    echo "<form method=post action=\"pscript2.php\">";
    echo "<table>";
    echo "<tr><td>Userid:</td>";
    echo "<td><input type=text name=first_name></td></tr>";
    echo "<tr><td>Password:</td>";
    echo "<td><input type=text name=last_name></td></tr>";
    echo "<tr><td colspan=2 align=center>";
    echo "<input type=submit value=\"Log in\"></td></tr>";
    echo "</table></form>";