Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Help with unexpected T_ELSE

Posted by: tyler.watkins May 24 2012, 01:53 PM


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);

?>

Posted by: Christian J May 24 2012, 06:44 PM

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.

Posted by: tyler.watkins May 24 2012, 07:18 PM

Now the only thing that comes up is the second page that says "incorrect username or password" even if it's right

Posted by: Christian J May 25 2012, 12:37 PM

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.

Posted by: Christian J May 26 2012, 01:05 PM

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-real-escape-string.php



Posted by: Ephraim F. Moya May 26 2012, 03:20 PM

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?




Posted by: tyler.watkins May 29 2012, 07:13 AM

What's the difference between MySQL and mysqli?

Posted by: jimlongo May 29 2012, 12:53 PM

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

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)