- <?php
-
session_start();
-
include("includes/config_db.php");
-
// Define $myusername and $mypassword
-
$myusername=$_POST['myusername'];
-
$mypassword=$_POST['mypassword'];
-
-
// To protect MySQL injection (more detail about MySQL injection)
-
$myusername = stripslashes($myusername);
-
$mypassword = stripslashes($mypassword);
-
$myusername = mysql_real_escape_string($myusername);
-
$mypassword = mysql_real_escape_string($mypassword);
-
-
$sql="SELECT * FROM members WHERE username='$myusername' and password=password('$mypassword')";
-
$result=mysql_query($sql);
-
-
// Mysql_num_row is counting table row
-
$count=mysql_num_rows($result);
-
// If result matched $myusername and $mypassword, table row must be 1 row
-
-
if($count==1){
-
// Register $myusername, $mypassword and redirect to file "login_success.php"
-
$_SESSION['myusername'] = $myusername;
-
$_SESSION['mypassword'] = $mypassword;
-
//session_register("myusername");
-
//session_register("mypassword");
-
header("location:login_success.php");
-
}
-
else {
-
?>
-
<table align="center" width="100%" border="0" cellpadding="0" cellspacing="1">
-
<tr><td align="center"><br/><br/>
-
<?
-
echo "Wrong Username or Password";
-
echo "<br/><input type=\"button\" name=\"Back\" value=\"Back\" onclick=\"javascript: history.go(-1)\" />";
-
?>
-
</td></tr></table>
-
<?
-
}
-
-
ob_end_flush();
-
?>
5 1497 Luuk 1,047
Recognized Expert Top Contributor
- where are the line numbers you are getting your errors on?
- why did you not use the '[code]' tags to post your code?
- you should not use the short tag '<?', always use the long one '<php'
Dormilich 8,658
Recognized Expert Moderator Expert
an $end error typically is caused by brace mismatch.
What is "?>" used for at line 30, 33, 36 and 38?
Dormilich 8,658
Recognized Expert Moderator Expert
context change between PHP and HTML.
Hi Kity.
I've cleaned up the code you posted, please bare in mind that most cases of bad coding are due to messy coding being difficult even for the author to follow.
Here's the cleaned code with comments on improvement. I have verified that the syntax is correct and working. - <?php
-
session_start();
-
include("includes/config_db.php");
-
// Define $myusername and $mypassword
-
$myusername = $_POST['myusername'];
-
$mypassword = $_POST['mypassword'];
-
-
// To protect MySQL injection (more detail about MySQL injection)
-
$myusername = stripslashes($myusername);
-
$mypassword = stripslashes($mypassword);
-
$myusername = mysql_real_escape_string($myusername);
-
$mypassword = mysql_real_escape_string($mypassword);
-
-
$sql = "SELECT * FROM `members` WHERE `username` = '{$myusername}' and password = password('{$mypassword}')";
-
$result = mysql_query($sql);
-
-
// Mysql_num_row is counting table row
-
//$count = mysql_num_rows($result); //You don't really need this, the MySQL query will return false if no results are found.
-
// If result matched $myusername and $mypassword, table row must be 1 row
-
-
if($result){ //Check to see if $result is true or false.
-
// Register $myusername, $mypassword and redirect to file "login_success.php"
-
$_SESSION['myusername'] = $myusername;
-
$_SESSION['mypassword'] = $mypassword;
-
//session_register("myusername");
-
//session_register("mypassword");
-
header("location:login_success.php");
-
}else {
-
//Condense the echo statements. You don't have to escape the double quotes, just invert the quotes that Echo uses.
-
echo '<table align="center" width="100%" border="0" cellpadding="0" cellspacing="1">
-
<tr><td align="center"><br/><br/>Wrong Username or Password<br/><input type="button" name="Back" value="Back" onClick="javascript: history.go(-1)" /></td></tr></table>';
-
//Also try to ensure that you reduce the number of times you open or close a PHP tag, they can be rather tricky to follow. It also helps to keep those pesky PHP Parsers where opening and closing php tags is not allowed happy.
-
}
-
-
ob_end_flush();
-
// EOF
-
?>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wescotte |
last post by:
The error message Parse error: syntax error, unexpected $end in FILE on
line X is one I run into frequently and I know the cause is I missed an
ending quote.
Is there an easy way to determine...
|
by: Brigitte Smith |
last post by:
I'm trying to make an image map and when I click on any part of it now it gives "Parse error: syntax error, unexpected T_VARIABLE in /usr/data2/hosted/angelauset/IMGMAPONE/map.php on line 11"
...
|
by: CYNTHIA CUTRER |
last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
...
|
by: Pete Burns |
last post by:
Creating a registration form and am getting a parse error on the line in the html form code for email address?!
Any thoughts please.
// Check for a first name:
if (empty($_POST)) {...
|
by: Vicki Hendra |
last post by:
Hi
I am new to php fullstop
I and colleagues have setup wordpress blogs for our local towns, giving the local businesses free advertisment.
Part of the problem started when using wordpress...
| |
by: Ann Madden |
last post by:
Hello - I am super green to php and mysql. I have received the following error: Parse error: syntax error, unexpected $end in C:\website\chart.php on line 84... I have been through the code matching...
|
by: togoode |
last post by:
Hello everyone, I'm new to php and to forums so please be gentle.
I'm trying to create my first form and php script for a website that will allow the user to send their info to me in an email....
|
by: James Long |
last post by:
I am getting the following error:
Parse error: syntax error, unexpected $end in E:\wamp\www\forums\view_topic.php on line 138
And i am a newbie..
I have been working on the code for ages and now...
|
by: Jeroendutch |
last post by:
Helle everyone,
I'm am not that familiar with HTML codes etc. but I do have a serious problem with my website witch gives the following code if I open it:
Parse error: syntax error, unexpected...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| | |