所以我正在一個項目上,我正在運行到幾個mysql & php錯誤。未定義的變量錯誤
第一個錯誤:
這是第一個錯誤相關的所有代碼
// Database Class
class Database {
public $_link, $_result, $_numRows;
public function __construct($server, $username, $password, $db){
$this->_link = mysql_connect($server, $username, $password) or die('Cannot Execute:'. mysql_error());
mysql_select_db($db, $this->_link);
}
public function disconnect(){
mysql_close($this->_link);
}
public function query($sql){
$this->_result = mysql_query($sql, $this->_link) or die('Cannot Execute:'. mysql_error());
$this->_numRows = mysql_num_rows($this->_result);
}
public function numRows() {
return $this->_numRows;
}
public function rows(){
$rows = array();
for($x = 0; $x < $this->numRows(); $x++) {
$rows[] = mysql_fetch_assoc($this->_result);
}
return $rows;
}
}
// Setup.php
$is_set = 'false';
global $company_name, $ebay_id;
if(isset($_POST['ebay_id'], $_POST['company_name'])){
$_ebay_id = $_POST['ebay_id'];
$_company_name = $_POST['company_name'];
$is_set = 'true';
} else {
// Silence is Golden!
}
$_service_database = new Database('localhost', 'root', 'password', 'chat-admin');
$_service_database->query("SELECT * FROM installs WHERE `identity` = '$mysqldb' AND `db_name` = '$mysqldb'");
if ($_service_database->numRows() == 0){
if($is_set == true){
$_service_database->query("INSERT INTO installs (ebay_id, name, db_name, identity) VALUES ('$_ebay_id', '$_company_name', '$mysqldb', '$mysqldb')");
}
} else {
// header("Location: index.php");
}
$_service_database->disconnect();
?>
<form name="setup" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<input placeholder="eBay Username" type="text" name="ebay_id">
<input placeholder="Company Name" type="text" name="company_name">
<input type="hidden" name="insert" value="true">
<input type="submit">
</form>
那麼這樣做是檢查是否定義的變量是在數據庫中,如果在提交表單的時候都沒有,那麼它插入我們的值,如果它們在數據庫中,它重定向到index.php,那麼我收到所有強大的MySQL num_rows *期望參數1是資源,布爾給定...,現在我已經遍地搜索,只發現死亡錯誤應該解決,這就是爲什麼你可以在函數查詢中的第16行看到它,現在雖然我得到每一個錯誤事情仍然有效,對我來說不是很好,因爲我可以將錯誤報告關閉,所以任何幫助都會很棒。此外,如果你看到像他們實際上是設置$ MySQLdb的,但在不同的頁面不確定的變量,它們是有效的
第二個錯誤:一個模板系統
這是所有與第二個錯誤
相關的簡單製作=功能function get_content_type($value){
if (strpos($value,'title:') === 0) {
$title = explode("title: ",$value);
$value = $title[1];
} else if (strpos($value,'css:') === 0) {
$css = explode("css: ",$value);
$value = $css[1];
} else if (strpos($value, 'js:') === 0) {
$javascript = explode("js: ", $value);
$value = $javascript[1];
} else {
// Silence is Golden
}
if($value == $title[1]){
echo '<title>'.$value.'</title>';
} else if ($value == $css[1]) {
echo '<link rel="stylesheet" href="'.$value.'">';
} else if ($value == $javascript[1]) {
echo '<script src="'.$value.'"></script>';
}
}
// Calling
get_content_type('title: Welcome to my site');
get_content_type('css: http://something.com/style.css');
get_content_type('js: http://code.jquery.com/jquery-latest.min.js');
一切都將按這個輸出
<title>Welcome to my site</title><link rel="stylesheet" href="http://somesite.com/style.css"><script src="http://code.jquery.com/jquery-latest.min.js"></script>
只有當我設置error_reporting(0);
我得到的錯誤是未定義的變量,因爲顯然我設置了一個,然後即時通訊不穩定,並設置另一個,所以最終只有1是正確的,儘管它已經輸出所有正確的。
UPDATE
第二錯誤:錯誤=
Notice: Undefined variable: css in C:\Server\www\hidie\libs\test.php on line 19
Notice: Undefined variable: title in C:\Server\www\hidie\libs\test.php on line 17
Notice: Undefined variable: title in C:\Server\www\hidie\libs\test.php on line 17
第一個錯誤:錯誤=
ERROR:Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given
您應該在您的問題中包含錯誤。我的水晶球在店裏。 –
另外,由於這是抽象的,因爲在查詢中一般調用它,num_rows將在該插入上返回false。 num_rows僅適用於select和show。你需要檢查其他操作受影響的行 –
我已經更新了錯誤,也是凱青我不明白你想告訴我什麼,我不是親在這個抱歉 – iConnor