The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Help with unexpected T_ELSE
tyler.watkins
post May 24 2012, 01:53 PM
Post #1


Novice
**

Group: Members
Posts: 27
Joined: 6-March 12
Member No.: 16,654




Parse error: syntax error, unexpected T_ELSE in /home/a3535994/public_html/login.php on line 121

I get this error message and idk why. I am trying to make a login system for my website. Here is my code.


<?php
$mysql_host = "***********";
$mysql_database = "*****";
$mysql_user = "*************";
$mysql_password = "*********";


$user = $_POST['username'];
$password = $_POST['password'];



$con = mysql_connect( "$mysql_host", "$mysql_user", "$mysql_password" );
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("$mysql_database", $con) or die (mysql_error());

$login_user = mysql_query("SELECT username FROM user");
$login_pass = mysql_query("SELECT password FROM user");

if ('$login_user' === '$user' && '$login_pass' === '$password');
{
?>

<!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org">
<script type="text/javascript" src="enter.js"></script>
<link href="style4.css" rel="stylesheet" media="all" type="text/css">
<script type="text/javascript">
function inputFocus(i){
if(i.value==i.defaultValue){ i.value=""; i.style.color=""; }
}
function inputBlur(i){
if(i.value==""){ i.value=i.defaultValue; i.style.color=""; }
}
</script>
<title>BLOCKS-Minecraft Maps and More</title>

<style type="text/css">
input.c2 {background-color:grey; text-style:times new roman;}
div.c1 {text-align: center}
</style>
</head>
<body>

<!--CONTAINER-->
<div class="container">
<div class="c1">
<div class="header"><br>
<h1>BLOCKS</h1>
<p>Minecraft Maps and More</p>
</div>

<!--LEFT SIDEBAR-->
<div class="lsbar">
<hr width="95%">
<a href="home.html">Home</a>
<hr width="95%">
<a href="http://blocks.forums.net.bz/">Forums</a>
<hr width="95%">
<a href="team.html">Our Team</a>
<hr width="95%">
<a href="tournaments.html">Tournaments</a>
<hr width="95%">
<a href="downloads.html">Downloads</a>
<hr width="95%">
<a href="register.html">Register</a>
<hr width="95%">
<!--<a href="#">Help</a>
<hr width="95%" color="black">--></div>

<!--CONTENT-->
<div class="content">
<div class="content-header c1">
<h1>What is Blocks?</h1>
</div>
<p>Welcome to Blocks. Here you can find and download Minecraft Maps and enter into awesome Minecraft Tournaments, oh and IT'S ALL FREE!!!</p>
<div class="content-header c1">
<h1>What are the Tournaments?</h1>
</div>
<p>The tournaments you can enter here are unlike any other! If you enjoy minecraft, then you should sign up for this site. The tournaments could range from crafting something in a specified space to creating a whole map! Check out the <a href="tournaments.html">Tournaments</a> page for more information.</p>
<div class="content-header c1">
<h1>When are the Tournaments?</h1>
</div>
<p>Check out the <a href="tournaments.html">Tournaments</a> page to find out when you can start siging up for tournaments and for a complete list of upcoming tournaments!</p>
<div class="content-header c1">
<h1>Worm's Blog</h1>
</div>
<p>Check <a href="worm.html">Here</a> to see updates and to leave comments!</p>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
</div>

<!--RIGHT SIDEBAR-->
<div class="rsbar-signin">

<h2>SIGN IN</h2>
<br>
<p>Logged In</p>
<hr width="95%">
<h2>Why Register?</h2>
<p>Registering with us will make you eligible to join our Minecraft Tournaments. You will also be entered into our mailings list and will recieve emails containing information on upcoming maps and tournaments.</p>
</div>

<!--FOOTER-->
<center><div class="footer">©Blocks.netne.net</div></center>
</div>
</div>
</body>
</html>

<!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
<?php
} else
{
?>
<!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org">
<script type="text/javascript" src="enter.js"></script>
<link href="style4.css" rel="stylesheet" media="all" type="text/css">
<script type="text/javascript">
function inputFocus(i){
if(i.value==i.defaultValue){ i.value=""; i.style.color=""; }
}
function inputBlur(i){
if(i.value==""){ i.value=i.defaultValue; i.style.color=""; }
}
</script>
<title>BLOCKS-Minecraft Maps and More</title>

<style type="text/css">
input.c2 {background-color:grey; text-style:times new roman;}
div.c1 {text-align: center}
</style>
</head>
<body>

<!--CONTAINER-->
<div class="container">
<div class="c1">
<div class="header"><br>
<h1>BLOCKS</h1>
<p>Minecraft Maps and More</p>
</div>

<!--LEFT SIDEBAR-->
<div class="lsbar">
<hr width="95%">
<a href="home.html">Home</a>
<hr width="95%">
<a href="http://blocks.forums.net.bz/">Forums</a>
<hr width="95%">
<a href="team.html">Our Team</a>
<hr width="95%">
<a href="tournaments.html">Tournaments</a>
<hr width="95%">
<a href="downloads.html">Downloads</a>
<hr width="95%">
<a href="register.html">Register</a>
<hr width="95%">
<!--<a href="#">Help</a>
<hr width="95%" color="black">--></div>

<!--CONTENT-->
<div class="content">
<div class="content-header c1">
<h1>What is Blocks?</h1>
</div>
<p>Welcome to Blocks. Here you can find and download Minecraft Maps and enter into awesome Minecraft Tournaments, oh and IT'S ALL FREE!!!</p>
<div class="content-header c1">
<h1>What are the Tournaments?</h1>
</div>
<p>The tournaments you can enter here are unlike any other! If you enjoy minecraft, then you should sign up for this site. The tournaments could range from crafting something in a specified space to creating a whole map! Check out the <a href="tournaments.html">Tournaments</a> page for more information.</p>
<div class="content-header c1">
<h1>When are the Tournaments?</h1>
</div>
<p>Check out the <a href="tournaments.html">Tournaments</a> page to find out when you can start siging up for tournaments and for a complete list of upcoming tournaments!</p>
<div class="content-header c1">
<h1>Worm's Blog</h1>
</div>
<p>Check <a href="worm.html">Here</a> to see updates and to leave comments!</p>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
</div>

<!--RIGHT SIDEBAR-->
<div class="rsbar-signin">

<h2>SIGN IN</h2>
<br>
<p>Incorrect Username or Password</p>
<hr width="95%">
<h2>Why Register?</h2>
<p>Registering with us will make you eligible to join our Minecraft Tournaments. You will also be entered into our mailings list and will recieve emails containing information on upcoming maps and tournaments.</p>
</div>

<!--FOOTER-->
<center><div class="footer">©Blocks.netne.net</div></center>
</div>
</div>
</body>
</html>

<!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->

<?php
}
mysql_close($con);

?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 24 2012, 06:44 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



Line 24 ends with a semicolon that shouldn't be there:

CODE
if ('$login_user' === '$user' && '$login_pass' === '$password');


Side-note: http://www.htmlhelp.com/reference/wilbur/misc/comment.html says:

QUOTE
Note that an "empty" comment tag, with just "--" characters, should always have a multiple of four "-" characters to be legal.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tyler.watkins
post May 24 2012, 07:18 PM
Post #3


Novice
**

Group: Members
Posts: 27
Joined: 6-March 12
Member No.: 16,654



Now the only thing that comes up is the second page that says "incorrect username or password" even if it's right
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 25 2012, 12:37 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



CODE
$login_user = mysql_query("SELECT username FROM user");
$login_pass = mysql_query("SELECT password FROM user");

The above returns the entire username and password columns in the DB table. You also need to loop through the column rows until you find one that matches the submitted form data.

CODE
if ('$login_user' === '$user' && '$login_pass' === '$password');

$login_user and $login_pass all the above are variables (not strings) so they shouldn't be quoted.

This post has been edited by Christian J: May 26 2012, 01:07 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 26 2012, 01:05 PM
Post #5


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(Christian J @ May 25 2012, 07:37 PM) *

The above returns the entire username and password columns in the DB table. You also need to loop through the column rows until you find one that matches the submitted form data.

I'm not very experienced with databases, but if the DB table contains lots of rows I guess it's more efficient to search for the submitted form data already in the SQL query? In that case you should sanitize the form data to prevent SQL injections.

See also http://php.net/manual/en/function.mysql-re...cape-string.php


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post May 26 2012, 03:20 PM
Post #6


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



What you get from a mysql_query is a resource handle, not a variable name. A resource handle id's the particular data you asked for in the SELECT statement. Now you have to look for the particular data pair of interest and do something with it.

So first: connect to the database,
Second: perform a query to get a resource id.
Third: use the resource id to translate the dataset to a form you can use.
Fourth: examine the dataset, entry by entry, to find the particular data you're looking for.
If you find it, do one thing,
If you don't find it, do another thing.

BTW, there is mysql and there is mysqli. Which one do you want to use?



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tyler.watkins
post May 29 2012, 07:13 AM
Post #7


Novice
**

Group: Members
Posts: 27
Joined: 6-March 12
Member No.: 16,654



What's the difference between MySQL and mysqli?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
jimlongo
post May 29 2012, 12:53 PM
Post #8


This is My Life
*******

Group: Members
Posts: 1,128
Joined: 24-August 06
From: t-dot
Member No.: 16



mysqli and PDO (Php Data Objects) are the newer object oriented PHP APIs to access mysql databases.

http://www.php.net/manual/en/mysqli.overview.php
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 06:08 AM