tpl文件
<script>
var xhr;function select1(){
if(window.ActiveXobjec){
xhr = new ActiveXobjec( "Microsoft.XMLHTTP");}
else if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}
var url ="index.php?c=shouye&a=dld";
xhr.open("POST",url,true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.onreadystatechange=callback;
var user=document.getElementById('username').value;
var pass=document.getElementById('password').value;
//alert(username);
//var data="username="+username+"&password="+password;
if(user!=''&&pass!='')
{
var username=document.getElementById('username').value;
var password=document.getElementById('password').value;
xhr.send("username="+username+"&password="+password);
}
else{
alert('账号或密码不能为空');
}
function callback(){
if(xhr.readyState==4)
{
if(xhr.status==200){
if(xhr.responseText=='you'){
alert('登陆成功');
window.open("index.php?c=shouye&a=show");
}else{
alert('登陆失败,请注册');
window.open("index.php?c=liuyan&a=zhuce");
}
}
}}
}
<body>
<input type="button" value="注册" οnclick="select1()"/>
</body>
.controller文件
public function dldAction(){
$username=$_POST['username'];
$password=$_POST['password'];
$dlModel=new dlModel('localhost','root','123','shouye');//file_put_contents("e://text.txt",$rows,FILE_APPEND);
$rows = $dlModel->dl($username,$password);
session_start();
$_SESSION["username"]=$username;
if($rows)
{echo 'you';}
else{echo 'kong';}
return $rows;
}
}
model文件
<?php
class dlModel extends baseModel{
public function insert($username,$password){
$sql="insert into user(user,password) value('".$username."','".$password."')";
//file_put_contents("e://text.txt",$sql,FILE_APPEND);
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
//file_put_contents("e://text.txt",$result,FILE_APPEND);
return $row;
}
public function dl($username,$password){
$sql = "select * from user where username='".$username."' and password='".$password."'";
$res = mysql_query($sql);
$rows=mysql_fetch_assoc($res);
//file_put_contents("e://text.txt",$rows,FILE_APPEND);
return $rows;
}
}
?>