ขอบคุณครับ แต่ก็ยัง งงๆ --* หรือผมโง่ 555
คือ ผมจะทำแบบ PHP+TPL โดยไม่มี html เรยหน่ะครับ
เพราะงั้นข้อ 4 ผมต้องร่าง tpl มาถูกรึเปล่าครับ
อันนี้ผมเอาโค้ดมาให้ดูครับ อาจมั่วไปนิด รบกวนดูให้หน่อยนะครับ
(ยังไม่เสร็จสมบูรณ์นะครับ เพิ่งลองจับผิดจับถูก ยังไม่ค่อยเก่งแบบนี้ครับ T^T)
changepass.tpl
{include file="header.tpl"}
<div id="subpage">
<h1>Edit Account</h1>
<p id="links"><a href="{$url->url_base}/home"> My URLs </a> | <a href="{$url->url_base}/changepass"> Edit Account </a>{if isset($smarty.session.is_admin)} | <a href="{$url->url_base}/admin"> Site Admin </a>{/if}</p>
<div id="login" class="clearfix">
{if $error == '1'}<center><span style="color:red;">{$error_message}</span></center>{/if}
{if $success == '1'}<center><span style="color:green;">Account Has Been Successfully Updated.</span></center>{/if}
<form action="{$url->url_base}/changepass" method="post">
<label for="username">Username:</label>
<input name="username" id="$username" siaze="30" type="text" value="{'username'}" readonly />
<input type="hidden" name="username" value="{'username'}" />
<label for="email">Email</label>
<input name="email" id="email" size="30" type="text" />
<label for="current_pass">Current Password:</label>
<input name="current_pass" id="current_pass" size="30" type="password" />
<label for="new_pass">New Password:</label>
<input name="new_pass" id="new_pass" size="30" type="password" />
<label for="new_pass2">Confirm New Password:</label>
<input name="new_pass2" id="new_pass2" size="30" type="password" />
<hr>
<input value="Edit Account" type="submit" />
<input type="hidden" name="task" value="editacount" />
</form>
</div>
</div>
<div class="divider"></div>
changepass.php
<?php
/** include header **/
include("header.php");
/** set page name **/
$page = 'changepass';
/** reset error & success vars **/
$error = 0;
$error_message = '';
$success = 0;
/** get value **/
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
/** change password **/
if(isset($_POST['task']) && $_POST['task'] == 'changepass')
{
/** get users curret information **/
$user = @mysql_fetch_array(@mysql_query("SELECT * FROM members WHERE id = '".$userid."' LIMIT 1"));
/** get current password **/
$current_pass = $user['password'];
/** get new password **/
$new_pass = $_POST['new_pass'];
/** check if new passwords match **/
if($new_pass != $_POST['new_pass2'])
{
$error = 1;
$error_message = 'New passwords don\'t match.';
}else
/** check old password **/
if($current_pass != sha1($_POST['current_pass']))
{
$error = 1;
$error_message = 'Current password does not match one on file.';
}else
/** check for empty fields **/
if(empty($_POST['current_pass']) || empty($_POST['new_pass']) || empty($_POST['new_pass2']))
{
$error = 1;
$error_message = 'Please fill all required fields.';
}else
/** no error?, update password **/
if($error != 1)
{
/** sha1 password **/
$new_pass = sha1($new_pass);
/** update password **/
mysql_query("UPDATE members SET password = '".mysql_real_escape_string($new_pass)."' WHERE id = '".$userid."'");
/** set success **/
$success = 1;
}
}
/** include footer **/
include("footer.php");
?>
chagepass.tpl.php
<?php /* Smarty version 2.6.26, created on 2010-10-11 15:40:30
compiled from changepass.tpl */ ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "header.tpl", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
?>
<div id="subpage">
<h1>Edit Account</h1>
<p id="links"><a href="<?php echo $this->_tpl_vars['url']->url_base; ?>
/home"> My URLs </a> | <a href="<?php echo $this->_tpl_vars['url']->url_base; ?>
/changepass"> Edit Account </a><?php if (isset ( $_SESSION['is_admin'] )): ?> | <a href="<?php echo $this->_tpl_vars['url']->url_base; ?>
/admin"> Site Admin </a><?php endif; ?></p>
<div id="login" class="clearfix">
<?php if ($this->_tpl_vars['error'] == '1'): ?><center><span style="color:red;"><?php echo $this->_tpl_vars['error_message']; ?>
</span></center><?php endif; ?>
<?php if ($this->_tpl_vars['success'] == '1'): ?><center><span style="color:green;">Account Has Been Successfully Updated.</span></center><?php endif; ?>
<form action="<?php echo $this->_tpl_vars['url']->url_base; ?>
/changepass" method="post">
<label for="username">Username:</label>
<input name="username" id="$username" siaze="30" type="text" value="<?php echo '$username'; ?>
" readonly />
<input type="hidden" name="username" value="<?php echo '$username'; ?>
" />
<label for="email">Email</label>
<input name="email" id="email" size="30" type="text" />
<label for="current_pass">Current Password:</label>
<input name="current_pass" id="current_pass" size="30" type="password" />
<label for="new_pass">New Password:</label>
<input name="new_pass" id="new_pass" size="30" type="password" />
<label for="new_pass2">Confirm New Password:</label>
<input name="new_pass2" id="new_pass2" size="30" type="password" />
<hr>
<input value="Edit Account" type="submit" />
<input type="hidden" name="task" value="editacount" />
</form>
</div>
</div>
<div class="divider"></div>