New to PHP

Please I need help on this code. I’m new to php and I’m having issues with this code that keeps giving me the parse error and I’ve been trying see the php syntax but I can’t get where I can study the php syntax

The Code:

<form action="Form" method="POST">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">

//$current_file = 'index.php'
if(isset($_POST["username"]) && isset($_POST["password"])){
   $Username = $_POST['username'];
   $Password = $_POST['password'];

   if(!empty($Username) && !empty($Password)){

     $query = "SELECT `Parishcode` FROM `users` WHERE `username`='$Username' AND `password`='$Password'"

     if($query_run = mysql_query($query)) {
        $query_num_rows = mysql_num_rows($query);
            echo 'Invalid Username/Password Combination';
        } else if($query_num_run==1){
               echo 'Welcome.'
   } else {
      echo ' Username and Password Mismatch.';



The Error:
Parse error: syntax error, unexpected ‘if’ (T_IF) in C:\xampp\htdocs\LOGINFORM.PHP on line 19

You’re getting the error because you missed the semicolon off the end of the previous line:

1 Like

Looks like a missing semicolon on the line with the query string.
Welocome to PHP, expect more of this. :smile:

1 Like

Thanks bro I just did that but gave error in line

It worked Thanks

You’re missing one here, too:

If you get a PHP error like that and there is nothing wrong with the line mentioned in the error, always check back to the previous line of code as often the error is there (e.g. missing semicolon).

1 Like

Thanks thanks Thanks it worked I can now continue my learning


As you’re learning, it would be a good idea to avoid using the mysql_* functions as these no longer exist in the current version of PHP. Use mysqli_* or better still PDO.


Please Bro can you help me with where I can get the example to use for this.


For an introduction to PDO I found these articles useful

For a more in depth look at PDO there is this:-

I know this gets said a lot, over and over again here. But when you are new it’s very easy to fall in the trap of learning out-dated stuff without knowing it. The mysql API is dead, there is no use in spending time learning yesterday’s methods.

I have this code:

<?php $current_file = $_SERVER['SCRIPT_NAME']; echo '$current_file'; ?>

but when it outputs it only outputs ‘$current_file’

That’s because you have quotes round $current_file.

You want
echo $current_file;

1 Like

When you use single quotes it is seen as a string.
A variable does not need quotes.

I’ve seen that but when I click on login button
it reads:

Access forbidden!

You don’t have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.24

I have my connection to the database like this:

$mysql_host = 'localhost';
$mysql_user = 'root';
$msql_pass = '';

$mysql_db = 'remmitance';

   if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass) || !@mysql_select_db($mysql_db)) {
      die('Couldn\'t Connect');


Assuming you sill have your original code, you have

form action="Form"

so the script is looking for a file names Form. I doubt that is what you mean. The action should be the PHP or HTML file that processes the user input.

Are you using an online tutorial?

I’ve actually changed it to:

<form action="<?php $current_file; ?>" method="POST">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">

got a new error msg:

Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\xampp\htdocs\LOGINFORM.PHP on line 13

Notice: Undefined variable: query_num_row in C:\xampp\htdocs\LOGINFORM.PHP on line 14
Invalid Username/Password Combination

I guess I might have to change to user defined error reporting

I ask again

I’m using a video tutorial