我正在开发一个jquery移动应用程序,它使用php从数据库中获取信息(例如用户登录)。但是我遇到了这个问题:我需要显示数据库中的具体信息取决于用户登录(客户端和proyects通过客户端的'project'字段和项目中的'id'相互关联)
我试图将字段'project'添加到'login'查询中,但是当我这样做时,应用程序无法记录
提前感谢您的帮助
----------- index.html --------------
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"/>
<link rel="stylesheet" href="theme/css/jquery.mobile.min.css" />
<link rel="stylesheet" href="theme/css/surinteractive.min.css" />
<link rel="stylesheet" href="theme/css/jquery.mobile.icons.min.css" />
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js"></script>
<script src="js/json.js"></script>
</head>
<body>
<div data-role="page" id="login" data-theme="a">
<header data-role="header" data-position="fixed">
<h1>Sistema de gestión de Requerimientos</h1>
</header>
<div data-role="content">
<div id="fm">
<form id="form">
<label for="username">User:</label>
<input type="text" value="" name="username" id="username"/>
<label for="password">Pass:</label>
<input type="password" value="" name="password" id="password"/>
<a data-role="button" id="login-button" data-theme="a" class="ui-btn-icon-right ui-icon-plus ui-btn-b">
Sign in
</a>
</form>
</div>
</div>
<footer data-role="footer" data-position="fixed" id="footer">
<p>© Copyright 2014 </p>
</footer>
</div>
<div data-role="page" id="menu" data-theme="a">
<header data-role="header" data-position="fixed">
<a href="#login" data-transition="slide" data-role="button" class="b_nuevo">Back</a>
<h3>Bugs List</h3>
</header>
<div data-role="content">
<h3>Welcome: </h3>
<ul data-role="listview" data-inset="true">
<li><a href="bugs/errors.html" data-transition="slide">Create a bug</a></li>
<li><a href="enh/enhacements.html" data-transition="slide">Create an enhacement</a></li>
</ul>
</div>
<footer data-role="footer" data-position="fixed" id="footer">
<p>© Copyright 2014</p>
</footer>
</div>
</body>
</html>
------------------ json.js --------------------------
$(document).on('pagebeforeshow', '#login', function(){
$('#login-button').on('click', function(){
if($('#username').val().length > 0 && $('#password').val().length > 0){
userObject.username = $('#username').val();
userObject.password = $('#password').val();
var outputJSON = JSON.stringify(userObject);
ajax.sendRequest({action : 'login', outputJSON : outputJSON});
} else {
alert('Please fill all requested information');
}
});
});
var ajax = {
sendRequest:function(save_data){
var address = null;
//address = 'http://127.0.0.1/app/inc/userValidation.php?jsoncallback=?';
$.ajax({url: address,
crossDomain: true,
data: save_data,
async: true,
beforeSend: function() {
// This callback function will trigger before data is sent
$.mobile.loading('show', {theme:"a", text:"Initializing...", textonly:true, textVisible: true});
},
complete: function() {
// This callback function will trigger on data sent/received complete
$.mobile.loading('hide');
},
success: function (result) {
if(result == "true") {
$.mobile.changePage( "#menu", { transition: "slide"} );
} else {
alert('Invalid login. Please try again!'); // In case result is false throw an error
}
// This callback function will trigger on successful action
},
error: function (request,error) {
// This callback function will trigger on unsuccessful action
alert('Connection error, please try again');
}
});
}
}
// We will use this object to store username and password before we serialize it and send to server. This part can be done in numerous ways but I like this approach because it is simple
var userObject = {
username : "",
password : ""
}
------------ userValidation.php -------------------
<?php
$jsonObject = json_decode($_REQUEST['outputJSON']); // Decode JSON object into readable PHP object
$username = $jsonObject->{'username'}; // Get username from object
$password = $jsonObject->{'password'}; // Get password from object
$connection = null;
$connection = new mysqli('127.0.0.1', 'xxxx', 'xxxx', 'xxxx');
$query = "SELECT * FROM clients WHERE username = '".$username."' and password = '".$password."'";
$result = mysqli_query($connection,$query);
$num = mysqli_affected_rows($connection);
if($num != 0) {
echo "true";
} else {
echo "false";
}
?>
数据库(结构和关系)
客户端 id,name,username,password,projectid,status,creation_date
项目 id,项目,描述,技术,状态,creation_date
虫子 id name projectid,type,environment,description,status,creation_date
projectid.clients = id.projects
id.projects = projectid.bugs
目标:将用户名存储在全局变量中,以便在另一个页面中恢复
答案 0 :(得分:0)
最后,我已经解决了这个问题,创建了一个名为sessions的新架构,当用户将其签名到应用程序时,它将存储在该架构中。在此之后,如果用户想要获取创建的错误列表,将调用新的sql语句来加入&#39;会话&#39;在那次搜索中