因此,我有一個簡單的工作用戶登錄腳本,它攜帶myusername和mypassword。根據用戶登錄從Mysql數據庫獲取特定數據
我正在嘗試(和失敗)要做的是回想一下用戶Mysql數據庫中的一條特定信息,以修改它們所在的頁面。
MYSQL DATABASE ('members'):
id:1
username:cornellmatt
password:encrypted(md5)
email:[email protected]
active: 0/1
**permission:1**
我需要提取的字段是權限,因爲它包含與用戶當前所處場景相關的數字。 爲了做到這一點,我認爲你在進入網頁上運行的Jquery登錄後,該鏈接connect.php
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$.get("connect.php", function(data) {
alert("Data Loaded: " + data);
});
據我所知,還有各種與我的JavaScript問題的那一刻,但現在我想讓服務器端的東西完成,所以我可以專注於JavaScript的完全 我的PHP的(當前)問題是,它似乎沒有從數據庫中得到任何東西,我知道它是連接,它只是不會迴應「權限」內的值;
connect.php:
<?php
include "Session.php";
$dbhost = "host";
$dbuser = "username";
$dbpass = "password";
$dbname = "databasename";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
//this selects everything for the current user, ready to be used in the script below
$result = mysql_query("SELECT * FROM members WHERE username = '$myusername' LIMIT 1");
//this function will take the above query and create an array
while($row = mysql_fetch_array($result))
{
//with the array created above, I can create variables (left) with the outputted array (right)
$permission = $row['permission'];
}
echo '<u><b>Permision ID:</b></u> - - No:' . $row['permission'] ;
?>
如果你想知道what'Session.php」,它是處理的啓動腳本,並且我知道我仍然登錄的原因。感謝Daryl Gill在之前的博文中幫助過我。
session.php文件
<?php
session_start();
if (!isset($_SESSION['Username']))
{
include "Logout.php";
exit;
// session is not set, so enforce logout
}
?>
所以,我的任務是,爲什麼不connect.php回顯值權限,甚至當我去的網頁直接?請幫助,我目前正在爲我的學生項目編寫代碼,並且已經圈了好幾天。
我從你的問題刪除的數據庫憑據。如果這些憑證有效,您可能需要刪除此問題,更改密碼並重新提問,因爲它們仍將出現在編輯歷史記錄中。 – 2013-03-22 11:46:01
還要在使用該密碼的其他每個服務上更改您的密碼。 – Alasjo 2013-03-22 11:48:06
謝謝,對不起,當我把它放在一個狀態,我的腦海裏炸了,感謝編輯它:) – 2013-03-22 12:04:16