<?php
include('inc/conn.php');
$action=$_GET['action'];

if($action=="baohu"){
    $userid=$_POST['userid'];
    $question=$_POST['question'];
    $answer=$_POST['answer'];
    $definequestion=$_POST['definequestion'];
    $defineanswer=$_POST['defineanswer'];
    $email=$_POST['email'];

    $sql="insert into etw_baohu(userid,questionid,answer,definequestion,defineanswer,email) value(".$userid.",'".$question."','".$answer."', '".$definequestion."','".$defineanswer."','".$email."' )";
    mysql_query($sql);
    echo "<script type=\"text/javascript\">alert('修改成功！');</script>";
    echo "<script type=\"text/javascript\">window.location.href=\"password.php\";</script>";
}
elseif($action=="mod")
{
   $userid=$_POST['userid'];
   $oldpwd=$_POST['oldpwd'];
   $newpwd=$_POST['newpwd'];
   $confrimpwd=$_POST['confrimpwd'];
  
   $sql="select * from etw_user where userid=".$userid;
   $results=mysql_query($sql);
   $old=mysql_fetch_array($results);
  
   if($old['password']==$oldpwd){
       if($newpwd == $confrimpwd){
        $up="update etw_user set password='".$newpwd."' where userid=".$userid;
		mysql_query($up);
		echo "<script type=\"text/javascript\">window.location.href=\"password.php\";</script>";
       }else{
		echo "<script type=\"text/javascript\">alert('两次输入的密码不一致！');</script>";
		echo "<script type=\"text/javascript\">window.location.href=\"password.php\";</script>";
	   }
    }else{
		echo "<script type=\"text/javascript\">alert('原始密码不正确！');</script>";
		echo "<script type=\"text/javascript\">window.location.href=\"password.php\";</script>";	
	}
	
}
 ?>