0

Trying to figure out why a script that worked perfectly well on Linux is not working on Windows server now after I moved it. It has the latest version of PHP installed and there is no reason it should not work on both. I have posted the code snippet, however if you need to see the other parts please let me know.

Thanks

It gives this error
Parse error: syntax error, unexpected $end in C:\inetpub\wwwroot\elitede.com\leisure\index.php on line 176

<?php
require('includes/header.php');?>

<div class="mid_content">
  <div class="category">
  <?php
if(isset($_POST['submit']))
{
$username = $_POST['user_name'];
$password = md5($_POST['password']);
/*$password = $_POST['password'];*/
$data = new main();
$login = $data->selectData("*","users",$username);
while($result = mysql_fetch_array($login))
  {
    $name = $result['user_name'];
	$pwd = $result['password'];
	$id = $result['id'];
	$role= $result['role'];
	
	$_SESSION['name'] = $name;
	$_SESSION['userID']=$id;
	
	
	if($username == $name && $password == $pwd && $role == "admin")
    {
		?>
  			<script>window.location.href="home.php";</script>
  		<?php
	 }
	 else if($username == $name && $password == $pwd && $role == "user")
	 {
	 	?>
  			<script>window.location.href="home.php";</script>
  		<?php
	 }
   	 else
	 {
     echo "Invalid Username and Password.";
   	 }	
  }
}

?>
<script language="javascript" type="text/javascript" src="validation.js"></script>
<div id="contentdiv">
 <div id="message"></div>
  <div align="center" style=" color: #4682B4;font-weight: bold;margin-bottom: 20px;">
  	<?php echo $site_name;?><br>Admin Panel</div>
	
	  <form name="login" method="post" action=""  onsubmit="return validlogin();">
		<div align="center">
		<table cellpadding="5" cellspacing="5">
		  <tr>
			<td>UserName:</td>
			<td><input class="textbox2" style="width:150px;" type="text" name="user_name" id="user_name"></td>
			<td id="usermsg"></td>
		  </tr>
		  <tr>
			<td>Password:</td>
			<td><input class="textbox2" style="width:150px;" type="password" name="password" id="password"></td>
			<td id="pwdmsg"></td>
		  </tr>
		  <tr>
			<td>&nbsp;</td>
			<td><input class="btnstyle" class="submit" type="submit" value="Login" name="submit"></td>
		  </div>
		  
		</table>
		</div>
	  </form>
</div>
</div>
<!--category end-->
</div>
<!-- <?php require('footer.php'); ?>

Edited by Narue: added code tags

4
Contributors
10
Replies
11
Views
5 Years
Discussion Span
Last Post by ppenguin
0

Yes I checked and it's the right script. There are others involved with it but this is the main one. Makes the error all the more strange. Is there any reason that something working on Linux would not work on Windows ?

0

The problem is because of an invalid close tag "{".


The error is not in the code you provided obviously because each are closed. :(

Edited by codewalkz: n/a

0

About the OS, there are functions and statements that will not work on one system or the other. But the script you have posted above will not make any trouble when ported.

0

Thanks Codewalkz so you are saying I should look at one of the other php programs that is called and try to find an unmatched "}"?

0

line 76 in the code above is not proper, it is mixed html / php
mixing javascript and php is not proper either

// get rid of the html comment tag on last line:
//from
<!-- <?php require('footer.php'); ?>
// to 
<?php require('footer.php'); ?>
// bad code!.
    if($username == $name && $password == $pwd && $role == "admin")
    {
    ?>
    <script>window.location.href="home.php";</script>
    <?php
    }
    else if($username == $name && $password == $pwd && $role == "user")
    {
    ?>
    <script>window.location.href="home.php";</script>
    <?php
    }
// good code:
    if($username == $name && $password == $pwd && $role == "admin")
    {
    header("Location: http://website/home.php");
    } 
    else if...
    {
     header("Location: http://website/home.php");
    }
    else
    {
    echo "invalid....";
    }

And in general the error:
Parse error: syntax error, unexpected $end
would mean that somewhere along the way you did not close an opened brace,
so yes you should look at all of the lines of php because you did not } close an { open brace somewhere.

0

Given that the JS in the original post does not make much sense as it is, I don`t see why one should not mix PHP with HTML or JS. Actually that is not even mixing, because all that PHP does is send the desired output to the browser. And if the desired output is JS or HTML then that is fine.

That being said, one of course always needs to be aware of the difference between server and client, and what that barrier implies for what you can do with the whole thing.

All of this does not mean that I don`t recommend a proper differentiation between the controlling and the presenting component.

0

I was saying his syntax was not proper.
why would you code

<!-- <?php include('me.php'); ?>

this does not make sense.
Also, I didn't mean you should not mix php with html or js, their implementation is just quirky, and I don't see how it would work properly, and it would be much better for clarity as well if they weren't doing a redirect in js, when it just as easily could have been done with php. Their code does not 'make sense' to me, nor is it straight forward and easily maintainable. not wanting to argue with you binary... you have some very valid points, I was just trying to point out to the ppenguin that there are better ways to code.

0

Totally agree, there are better ways to redirect. About the last line thou: As we all figured that the OP did not post the whole script, I guess the HTML comment will be closed in the following lines ;-)

0

I agree about the coding being weird. I didn't write it, have not coded in awhile. I am merely the IT person that needs to get it working. The weirdest thing is it worked perfectly fine on my linux server and it's the windows transition that is causing the weird problems.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.