123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- header("Content-Type: text/html; charset=utf8");
- function getJson($result,$message){
- $json_array = array(
- "result"=>$result,
- "message"=>$message
- );
- return json_decode($json_array);
- }
- include('database_connect .php');//链接数据库
- $name = $_POST['name'];//post获得用户名表单值
- $passowrd = $_POST['password'];//post获得用户密码单值
- if ($name && $passowrd){//如果用户名和密码都不为空
- $sql = "select * from user_info where user_name = '$name' and password='$passowrd'";//检测数据库是否有对应的username和password的sql
- $result = mysql_query($sql);//执行sql
- $rows=mysql_num_rows($result);//返回一个数值
- if($rows){//0 false 1 true
- echo getJson(0,"登陆成功")//如果成功跳转至welcome.html页面
- exit;
- }else{
- echo getJson(-1,"用户名或密码错误");
- }
- }else{//如果用户名或密码有空
- echo getJson(-2,"表单填写不完整");
- }
- mysql_close();//关闭数据库
|