MySQL Problems with my Codes

Hi, So I recently learned about MySQL. And I have been getting this error:
Parse error: syntax error, unexpected ‘)’ in C:\Program Files\Xampp\htdocs\login.php on line 59
If someone could help me determine what the problem is, Could someone help me and even correct my codes (that are wrong)?
These are My Codes:

<title>The Social Portal</title>
<body background="Portal.jpg">
<embed src=music.mp3 autostart=true loop=true width=2 height=0></embed>
<font face="Century Gothic" color="#FFFFFF" size="5">
<form action="login.php"method="post">
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<html>
<body>
<form method="post" action="login.php">
Username:<input type="text" name="username" /> 
Password:<input type="password" name="password" /> 
<input type="submit" name="submit" value="Login In" />
</form>
</body>
</font>
</html>

<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "accounts";
mysql_connect_db ($host, $user, $pass);
mysql_connect_db ($db);
if (isset($_POST['username'])){
$username = $_POST ['username'];
$password = $_POST ['password'];
$sql = "SELECT * FROM users WHERE username ='" .$username."' AND password ='" .$password. "' LIMIT 1 ";
$res = mysql_query ($sql);
if (mysql-num-rows($res)==1){
echo "You have succesfully logged in!";
exit ();
} else {
echo "Invalid login information. Please return to the previous page.";
exit ();
}
}
?>
<?php
if (isset($_POST['submit'])){
$user_name = $_POST ['name'];
$user_pass = $_POST ['pass'];
if ($user_name== ' ' ){
echo "<script>alert ('Please enter your name!')</script>";
exit ();
}
if ($user_pass== ' ') {
echo "<script> alert ('Please enter your password!') </script>";
exit ();
}
$query ="insert into users(user_name, user_pass) values ('$user_name', '$user_pass')";
if (mysql_query)){
echo "<script>alert ('Login successful!')</script>";
}
}
?>  

<font face="Century Gothic" color="blue" size="12">
<br>
<br>
<br>
<center>Don't Have an Account?</font>
<font face="Century Gothic" color="orange" size="12">
<center>Sign up for The Social Portal:</font>
<br>
<a href="register.php"><img src="register.png"></a>
</body>
</html>


My guess is it will be this:


if (mysql_query)){

The error message tells you the problem is on line 59 - although that isn’t always the case with parse errors, in this case line 59 is the problem - you have one open bracket, and two close brackets.

Don’t you also get an error message for


if (mysql-num-rows($res)) {

I would think that function name should read mysql_num_rows()

But, you need to look at using PDO or mysqli, especially if you’re still learning PHP - the old-style mysql calls (all those functions that start with “mysql”) are being deprecated from future versions so you’re wasting time learning an old-style method of accessing the database.

There’s a sticky to an article on this forum showing how to switch.

The code is also wide open to SQL injection attack as the user submitted data is not at the very least being escaped. Prepared statements should be used when dealing with user submitted data