Log in

View Full Version : Resolved Parse error: syntax error unexpected 'echo'



Kage Kazumi
10-21-2012, 07:14 PM
This error pops for the following line:



<?php if(isset ($error)) (echo '<div id="login-errors">'.$error.'</div>'); ?>


EDIT

If I change "echo" to "print" it returnes no errors, but then it messes up the page layout and prints the following in the upper left corner:



array (size=3)
'username' => string 'dfdf' (length=4)
'password' => string 'dfdfd' (length=5)
'logintoadmincenter' => string 'Login' (length=5)


However, it does do somewhat, what it should be doing which is "print" 'Invalid Credentials' in the DIV.

djr33
10-21-2012, 07:38 PM
<?php if(isset ($error)) {
echo '<div id="login-errors">'.$error.'</div>'
} ?>
Use {} for if statements, rather than (). And don't end that with a ;. I'm not exactly sure what's not working there, but the code was written incorrectly, and it should now work.

Kage Kazumi
10-21-2012, 07:49 PM
<?php if(isset ($error)) {
echo '<div id="login-errors">'.$error.'</div>'
} ?>
Use {} for if statements, rather than (). And don't end that with a ;. I'm not exactly sure what's not working there, but the code was written incorrectly, and it should now work.

That creates a new error:

Parse error: syntax error, unexpected '}', expecting ',' or ';'

Here is what I have written incase I did it wrong:



<?php if(isset ($error)) { echo '<div id="login errors">'.$error.'</div>' } ?>


Alright I added ";" at the end and it fixed it, but now the page is breaking layout and displaying:



array (size=3)
'username' => string 'dfdf' (length=4)
'password' => string 'dfdfd' (length=5)
'logintoadmincenter' => string 'Login' (length=5)


So why is this PHP breaking my HTML layout and adding that code in the upper left corner which is not what it is suppose to do:

My PHP



<?php
session_start();
if($_POST && isset($_POST['logintoadmincenter']))
{
include_once '/include/connection.php';

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

if (empty($username) && empty($password))
{

$error = "Please fill in the required fields";
}
else
{
print "<pre>";
var_dump($_POST);
$username = strip_tags ($username);
$password = strip_tags ($password);

$username = mysql_real_escape_string ($username);
$password = mysql_real_escape_string ($password);
$password = md5($password);
$sql = mysql_query("SELECT * From Members WHERE name = '$username' && password = '$password' LIMIT 1") or die (mysql_error ());
$num_rows = mysql_num_rows ($sql);
if ($num_rows == 1)
{
$rows = mysql_fetch_array($sql);
extract ($rows);

$_SESSION['username'] = $name;
$_SESSION['level'] = $access_level;

if (isset ($$_SESSION['username']));
{
$update = msql_query("UPDATE Members SET last_log_time = now()") or die(mysql_error());

header("location: index.php");
}
}
else
{
$error = 'Invalid Credentials';
}
}
}
?>


Never mind I found the issue:



print "<pre>";
var_dump($_POST);

djr33
10-21-2012, 08:19 PM
Alright I added ";" at the end and it fixed it,Oops, I missed that.