วันเสาร์ที่ 5 กันยายน พ.ศ. 2558

การเปลี่ยนรหัสผ่าน

<?php

mysql_query("update student set password='$_POST[password]'
where id='{$_SESSION['student']['id']}'");
alert_text('เปลี่ยนรหัสผ่านใหม่เรียบร้อยแล้ว');
redirect("index.php");


?><script  language="javaScript">
function check(){
if(document.form1.newpassword.value ==""){
 alert("กรุณาระบุรหัสผ่านใหม่");
 document.form1.newpassword.focus();
 return false;
 }

  else if (document.form1.repassword.value != document.form1.newpassword.value){
  alert("รหัสผ่านไม่ตรงกัน");
  document.form1.repassword.focus();
  return false;
  }else{return true;}
}
</script>
<table width="100%" height="255"  border="0">
  <tr>
    <td valign="top"><div align="center"><h1>เปลี่ยนรหัสผ่านใหม่</h1>
<form action="" method="post" name="form1" id="form1" onsubmit="return check()">
  <table width="343" border="0" align="center">
 
    <tr>
      <td width="127"><div align="right">รหัสใหม่</div></td>
      <td width="206"><input type="password" name="newpassword" id="s" maxlength="20" /></td>
    </tr>
    <tr>
      <td><div align="right">ยืนยันรหัสอีกครั้ง</div></td>
      <td><input type="password" name="repassword" id="s"  maxlength="20"/></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" id="button" value="ตกลง" />
      <input type="reset" name="button2" id="button2" value="ยกเลิก" /></td>
    </tr>
  </table>
</form>
</div></td>
  </tr>
</table>

logout

<?php
require_once('connect.php');
unset($_SESSION['student']);
unset($_SESSION['login']);
redirect('index.php');
exit();

?>

function checkUser()

function checkUser()
{
// if the session id is not set, redirect to login page
if (!isset($_SESSION['login'])) {
redirect("index.php");
exit();
}

}