function changepass(){
var oldpass=document.mychange.oldpass.value;
var pass=document.mychange.pass.value;
var passconf=document.mychange.passconf.value;
var chkpass=pass.length;
var user=getCookie("user");
if(oldpass=="" || pass=="" || passconf==""){
alert("Please enter Password");
}
else if(chkpass<8){
alert("Please enter at least 8 characters.");
}
else if(pass!=passconf){
alert("Please enter a valid Password.");
}
else{
var req;
if(window.XMLHttpRequest) req=new XMLHttpRequest();
else if(window.ActiveXObject) req=new ActiveXObject("Microsoft.XMLHTTP");
else{
alert("Browser not support"); return false;
}
req.onreadystatechange=function(){
if(req.readyState==3){
document.getElementById("area")
x.innerHTML='<img src="images/indicator_bar.gif">';
}
if(req.readyState==4){
var x=document.getElementById("area");
x.innerHTML="Change Password Finish <br>";
}
else{
var x=document.getElementById("area");
x.innerHTML="<img src=img/wait.gif>";
}
}
}
var str=Math.random();
var querystr="";
querystr+="changepassword.php";
querystr+="?var="+str;
querystr+="&user="+user;
querystr+="&oldpass="+oldpass;
querystr+="&pass="+pass;
req.open("GET",querystr,true);
req.send(null);
}
Code (PHP)
/*changepassword.php*/
<?php
$strUsername = $_GET["user"];
$strOldPassword = $_GET["oldpass"];
$strPassword = $_GET["pass"];
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$sql = "select * from account where username = '$strUsername' and password='$strOldPassword'" ;
$result = mysql_query($sql) ;
$row = mysql_num_rows($result) ;
if($row<=0)
{
echo $row;
}
else
{
$sql = "UPDATE account SET password = '".$strPassword."' WHERE username = '".$strUsername."' ";
$query = mysql_query($sql) or die ("Error Query [".$sql."]");
}
echo $row;
mysql_close($objConnect);
?>
พอกดเปลี่ยน Password แล้วมันขึ้น Change Password Finish นะคับ แต่ใน SQL มันไม่เปลี่ยนอะครับ
ผิดตรงไหน ผู้รู้ช่วยหน่อยนะครับ T T