我在一個名爲navbar.php的文件上有我的導航欄腳本。我將該文件包含在我網站的所有其他頁面的頂部。我現在要做的是自定義導航欄名稱誰登錄。假設我有一個名爲帳戶process.php與變量$name = 'Bob'
的PHP文件。我無法使這個變量顯示在導航欄中。將不同頁面的php變量顯示到html頁面
這裏是我的帳戶process.php:
<?PHP
//VARS: gets user input from previous sign in page and assigns it to local variables
//$_POST['signin-email'];
//$_POST['signin-pass'];
$signin_email = $_POST['signin-email'];
$signin_pass = $_POST['signin-pass'];
// connects to MySQL database
include("config.inc.php");
$link = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name,$link);
// checking for user input in the table
$result = mysql_query("SELECT * FROM table WHERE email = '$signin_email' AND password = '$signin_pass'");
if (mysql_num_rows($result) > 0) { // if the username and password exist and match in the table
echo "Account Found";
$account_arr = mysql_fetch_array($result); // contains all the data from the user's MySQL row
echo print_r($account_arr);
}
else { // if username and password don't match or they aren't found in the table
echo "The email or password you entered is incorrect.";
}
?>
我試圖訪問navbar.php的$account_arr
變量,所以我可以在頂部顯示用戶的名字。我已經嘗試過,包括account-process.php在navbar.php與<?php include('account-process.php') ?>
,然後訪問導航欄的html中的變量,但是當我嘗試這個時,頁面會變成空白。
navbar.php只是基本的腳本爲固定的導航欄與一些信息。爲什麼當我嘗試在其中包含php文件時會變成空白?
感謝
因爲你沒有指示Apache的治療'.html'文件作爲PHP它變成空白。將其命名爲「navbar.php」,它將起作用。 – 2014-08-31 02:49:26
對不起,navbar實際上是一個php。它應該是navbar.php。讓我編輯這個問題。 – applemavs 2014-08-31 02:50:37
好東西,我不覺得過分自信;) – 2014-08-31 02:51:00