所以我正在一个项目上,我正在运行到几个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