2015-07-21 121 views
-2

我收到以下錯誤,當我運行PHP腳本調用功能。呈現下面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> 

任何建議來解決這個問題。

+0

初始化變量$ DBO – Konstantin

+0

哪裏是你的連接更改您的config.php? – Rizier123

+0

您的模板也有一些HTML錯誤,但我想你會在實際連接到數據庫時找到它們。 – RiggsFolly

回答

0

<?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"); 


?> 
+0

也很好,檢查連接是否成功,而不是假設它會工作 – RiggsFolly

+0

哦謝謝@RiggsFolly –