我有一個函數的任何一個默認值,例如:PHP函數沒有定義
function output_message($message="") {
if (!empty($message)) {
return "<p class=\"message\">{$message}</p>";
} else {
return "";
}
}
我然後我回蕩在我的日誌形式的消息。如果有錯誤,它會顯示一條消息,但如果沒有錯誤,它應該什麼也不做。當我的頁面加載它說我的功能沒有定義。以下是我的html頁面。
<?php
require_once("../../includes/functions.php");
require_once("../../includes/session.php");
require_once("../../includes/database.php");
require_once("../../includes/user.php");
if($session->is_logged_in()) {
redirect_to("index.php");
}
// Remember to give your form's submit tag a name="submit" attribute!
if (isset($_POST['submit'])) { // Form has been submitted.
$username = trim($_POST['username']);
$password = trim($_POST['password']);
// Check database to see if username/password exist.
$found_user = User::authenticate($username, $password);
if ($found_user) {
$session->login($found_user);
redirect_to("index.php");
} else {
// username/password combo was not found in the database
$message = "Username/password combination incorrect.";
}
} else { // Form has not been submitted.
$username = "";
$password = "";
}
<html>
<head>
<title>Photo Gallery</title>
<link href="../stylesheets/main.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>Photo Gallery</h1>
</div>
<div id="main">
<h2>Staff Login</h2>
<?php echo output_message($message); ?>
<form action="login.php" method="post">
<table>
<tr>
<td>Username:</td>
<td>
<input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" />
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type="password" name="password" maxlength="30" value="<?php echo htmlentities($password); ?>" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="Login" />
</td>
</tr>
</table>
</form>
</div>
<div id="footer">Copyright <?php echo date("Y", time()); ?>, Kevin Skoglund</div>
</body>
</html>
<?php if(isset($database)) { $database->close_connection(); } ?>
我不知道,因爲我的功能我在功能設置$消息的默認值爲什麼我收到此錯誤。 output_message($消息= 「」)。
有人可以看看我的代碼,並告訴我爲什麼它告訴我我的功能沒有定義。謝謝。
在之前缺少一個關閉'?>'? output_message()函數在哪裏定義?另外,我建議你爲開發啓用體面的錯誤報告。將它放在腳本的頂部; 'ini_set('display_errors','On'); error_reporting(E_ALL);' – Phil 2012-01-13 01:11:19
你也可能想要初始化'$ message'變量來避免未定義變量的警告(與未定義的函數無關......)。 – jeroen 2012-01-13 01:15:53
@phil它位於文檔頂部包含的包含文件夾中的函數文件中。 – user982853 2012-01-13 01:32:03