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">
</form>
<?php
//$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);
if($query_num_row==0){
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
SamA74
October 25, 2016, 1:02pm
3
Looks like a missing semicolon on the line with the query string.
Welocome to PHP, expect more of this.
1 Like
Thanks bro I just did that but gave error in line
You’re missing one here, too:
tosinonabanjo:
echo ‘Welcome.’
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
Thanks
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.
3 Likes
Please Bro can you help me with where I can get the example to use for this.
Thanks
SamA74
October 25, 2016, 1:59pm
10
For an introduction to PDO I found these articles useful
For a more in depth look at PDO there is this:-
https://www.sitepoint.com/community/t/looking-for-feedback-on-a-pdo-tutorial-i-wrote/215875?u=sama74
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’
Gandalf
October 25, 2016, 2:11pm
12
That’s because you have quotes round $current_file.
You want
echo $current_file;
1 Like
SamA74
October 25, 2016, 2:13pm
13
When you use single quotes it is seen as a string.
A variable does not need quotes.
Thanks
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
localhost
Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.24
I have my connection to the database like this:
<?php
$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');
}
?>
Gandalf
October 25, 2016, 2:19pm
16
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">
</form>
got a new error msg:
/index.php
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
no
I’m using a video tutorial