Author Topic: Annoying smarty error  (Read 615 times)

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Annoying smarty error
« on: February 02, 2009, 05:50:32 PM »
Okay so in taking the advice of the members of the forum, I've taken just the login,register,change pass from the tutorial code,and am creating my own code for the rest for time sakes, this way I can check my logged in vs logged out security etc. Now for no apparent reason after deleting the tutorial files from my game folder, my login.tpl is no longer working and creating this error.

Code: [Select]
Warning: Smarty error: unable to read resource: "login.tpl" in C:\xampp\htdocs\smarty\libs\Smarty.class.php on line 1092
Now normally I would assume my template folder directory was not properly located in my smarty.php file.And here is where it becomes annoying, every OTHER page I either made, or took from the tutorial works perfectly as far as displaying. None of them result in any smarty errors that are not from my lack of coding skills :P So this being said am sure its something simple and what not so if anyone can spot it, because I have gone over this code countless times and see no reason for the error.

login.tpl

Code: [Select]
<html>
<head>
<title>Login</title>
</head>
<body>
{if $error ne ""}
<span style='color:red'>Error: {$error}</span>
{/if}
<p><a href='register.php'>Not registered yet?</a></p>
<form action='login.php' method='post'>
Username: <input type='text' name='username' id='username' value='{$smarty.post.username}' /><br />
Password: <input type='password' name='password' /><br />
<input type='submit' value='Login' />
</form>
<script type='text/javascript'>
document.getElementById('username').focus();
</script>
</body>
</html>

login.php
Code: [Select]
<?php

// put full path to Smarty.class.php
include 'smarty.php';

$smarty = new Smarty();


session_start();
if(
$_POST) {
require_once 'config.server.php';
$username $_POST['username'];
$password $_POST['password'];
$conn mysql_connect($dbhost,$dbuser,$dbpass)
or die ('Error connecting to mysql');
mysql_select_db($dbname);
$query sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s') AND password='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string(md5($password)));
$result mysql_query($query);
list($count) = mysql_fetch_row($result);
if($count == 1) {
$_SESSION['authenticated'] = true;
$_SESSION['username'] = $username;
header('Location:changepass.php');
} else {
$query sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s') AND password='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string(md5('saltgoeshere' $password)));
$result mysql_query($query);
list($count) = mysql_fetch_row($result);
if($count == 1) {
$_SESSION['authenticated'] = true;
$_SESSION['username'] = $username;
$query sprintf("UPDATE users SET last_login = NOW() WHERE UPPER(username) = UPPER('%s') AND password = '%s'",
mysql_real_escape_string($username),
mysql_real_escape_string(md5('saltgoeshere' $password)));
mysql_query($query);
$query sprintf("SELECT is_admin FROM users WHERE UPPER(username) = UPPER('%s') AND password='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string(md5('saltgoeshere' $password)));
$result mysql_query($query);
list($is_admin) = mysql_fetch_row($result);
if($is_admin == 1) {
header('Location:admin.php');
} else {
header('Location:main.php');
}
} else {
$error 'There is no username/password combination like that in the database.';
}
}
}

$smarty->assign('error',$error);
$smarty->display('login.tpl');
?>

it has to be something on these 2 pages, because like I stated earlier, every other page works fine with smarty, which leads me to be leave that it is not a proper directory instruction.
People Like You, Are the Reason People Like Me Need Medication

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Annoying smarty error
« Reply #1 on: February 02, 2009, 11:52:12 PM »
You are re-declaring your smarty object and killing the path references in the original object...

In your login.php remove the line: $smarty = new Smarty;

Creating online addictions, one game at a time:

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Annoying smarty error
« Reply #2 on: February 02, 2009, 11:59:48 PM »
BTW... after making a call to header("location: ????");

You need to put an exit after the call to header, the PHP code will keep executing on that page, header does NOT do an immediate jump to the page and stop code execution. The way you have the if/else structure on that page it doesn't look like it would be a problem but if you keep coding like that in the future it might. I myself learned this leason the hard way ;)

Also I see this in a lot of other peoples coding, so don't take it personally :)

do not do if( $_POST) for a check to see if you have a post, do if( isset($_POST) )

You need to see if the post array has been set, not to see if it's blank...

Hope this helps ya out :) Everything looks pretty good. So of your code styling reminds me of when I started.. Another tip, I like how you made config.server.php, but you are also including smarty.php

I outlined a while back the structure I use.. I think this may help you...

Create a common.lib.php in that file put your include and definitions of smarty in there, also on that one put your require for your server. Now you only ever have to include on file ;)



Creating online addictions, one game at a time:

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: Annoying smarty error
« Reply #3 on: February 03, 2009, 12:26:13 AM »
actually its the tutorial code which i believe belongs to bbgames, aside from the smarty error, which was all me. And to be honest i stole the config.server idea from your post =P I leave the smarty separate only due to the fact for the time being am testing this locally, now that i got smarty to work with xampp, this way I move all my files over, but just dont copy config.server and smarty and am up and running, my "live" server already has those setup for it in a identical fashion.

Oh and btw it worked thanks a ton
People Like You, Are the Reason People Like Me Need Medication

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal