PHP未定义的对象错误并在非对象错误上调用函数

时间:2015-07-21 10:41:02

标签: php html

运行php脚本时出现以下错误。

错误如下所示

Errors Given

以下是代码。

config.php文件

<?Php

$dbhost_name = "localhost";
$database = "datacentre";  // Your database name
$username = "root";                  //  Login user id 
$password = "";                  //   Login password

define( "TEMPLATE_PATH", "templates" );


define( "ADMIN_USERNAME", "username" );

define( "ADMIN_PASSWORD", "password" );


?> 

register.php文件

<?php
require "config.php";

$requests = array();

$sql = "SELECT request FROM request_type";

foreach ($dbo->query($sql) as $row)
{
    $requests[] = $row['request'];
}

include('/templates/file.template.php');

file.template.php代码

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="layout.css">

<title>Title of the document</title>
</head>
<div>
<body>
<?php
include('header.php');
?>


<section id="sidebar">

</section>

<section id="content">


<form class="form" action="insert.php" method="post" name="access_form">

<ul>

<li>
<h2>Please Fill The Form</h2>

</li>



<li>
     <label for="firstname">First Name</label> 
        <input name="firstname" id="keyword" type="text" placeholder="type first name (required)" required />             

</li>

<li>
     <label for="lastname">Last Name</label>
     <input name="lastname" id="lastname" type="text" placeholder="type second name (required)" required />
</li>

<li>

<label for="request" id="officallabel">Type of Request</label>
<input name="request" id="request" list="request1" />
        <datalist id="request1" >
            <?php foreach ($requests as $request): ?>
                <option value="<?php echo $request; ?>" />
            <?php endforeach; ?>
        </datalist>
</li>

<li> 
    <label for="purposebuttons" id="officallabel">Purpose</label> 
   <div  class="radio">
    <input type = "radio"
           name = "purposebuttons"
           id = "official"
           value = "Official" />
    <label id="official" for="official">Official</label>

    <input type = "radio"
           name = "purposebuttons"
           id = "unofficial"
           checked = "checked" 
           value = "denied" />
    <label id="unofficial" for="unofficial">Unofficial</label>
  </div>
</li>


<li>
   <label for="description">Description</label>
   <textarea name="description" id="description" placeholder="type description (required)" required ></textarea>
</li>


<div>         
          <input type = "radio"
                 name = "approvalbuttons"
                 id = "approved"
                 value = "Approved"
          <label for = "approved">Approved</label>

          <input type = "radio"
                 name = "approvalbuttons"
                 id = "denied"
                 checked = "checked" 
                 value = "Denied" />
          <label for = "denied">Denied</label>

        </div>


<li>  
   <label for="approvedby">Approved By</label>
   <input name="approvedby" id="approveby" type="text" placeholder="approval name (required)" required />
</li> 

<p>
          <input type = "reset" class="submit"/>
          <input type = "submit" class="reset"/>
        </p>    

</section>


</ul>
</form>

<aside></aside>
<span id="allowance" ></span>

<?php
include('footer.php');
?>
</body>
</div>
</html>

有任何解决问题的建议。

1 个答案:

答案 0 :(得分:0)

使用

更改config.php
<?php

$dbhost_name = "localhost";
$database = "datacentre";  // Your database name
$username = "root";                  //  Login user id 
$password = "";                  //   Login password
$dbo = new mysqli($dbhost_name , $username, $password, $database );
if ($dbo->connect_error) {
  die("Connection failed: " . $dbo->connect_error);
}
define( "TEMPLATE_PATH", "templates" );


define( "ADMIN_USERNAME", "username" );

define( "ADMIN_PASSWORD", "password" );


?>