我在一个名为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