English 中文(简体)
体质功能没有定义
原标题:Php function not define

我的职能是毫无缺省价值,例如:

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(); } ?>

我不敢肯定,为什么我正在发现这一错误,因为我的职责是确定该职能中拖欠的年金价值。 产出——工资($message=”

人们可以看我的法典,告诉我,为什么没有界定我的职能。 感谢。

问题回答

Based on your comment, it seems that it is not the function that is not defined, but the variable.

问题并不在于职能本身,如果该职能没有变数,那么你可变的<条码>_$message就定在空洞中。

问题在于你的职责:

<?php echo output_message($message); ?>

这里,你把你的职能称为“_$message,但与你职能中可变的_$message完全无关。 这一全球变量并不存在,这就是为什么要让你们发出警告。

你们如何界定你的职能,意味着你可以称之为:

<?php echo output_message(); ?>

如果没有问题,如果无法提供变数,则该功能中的<代码>_message变量被设定为空洞。

然而,使用:

<?php echo output_message($any_variable_name); ?>

如果在你所处范围内(此处为全球范围)没有界定$_variable_name,就会发出警告。

我真心实意地知道你在哪里使用产出————但我的第一gues是,这些职能“直接”可能是问题。

这些职能大部分时间都是这样:

   header(  Location: http://some_where_on.yourweb  );

检查一下,你已经将这项权利列入“.php”档案中,你正在利用产出——工资功能。

此外,我建议遵循Phil和jeroen的意见:

  • missing ?> before tag
  • add init_set("display_errors","On"); error_reporting(E_ALL)
  • initialize variables like $message to avoid warnings and side effects
  • Try not to mix rendering with logic (this one is mine)




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签