我有两个页面:
1。Common.php,代码是:
<?php
$fileSystemDec = "/";
$newsDocRootURL = ".." . $fileSystemDec . ".." . $fileSystemDec . "news" . $fileSystemDec . "news";
$dbHost = "localhost";
$dbName = "fudandb";
$dbUser = "root";
$dbPwd = "";
$applicationRootPath = "/cn";
$imagePath = $applicationRootPath . "/action/Images";
$CSSFile = $applicationRootPath . "/style.css";$insertImageTag = "<images/>";
$insertContentTag = "<news_content/>";
$insertTitleTag = "<title/>";
$insertDateTag = "<date/>";$newsCountAPage = 7;$newsTable = "news";
?>2。index.php 部分代码是:<? include("include/common.php") ?>
<? include("include/commonfunction.php") ?>
<?php
$db = mysql_connect($dbHost, $dbUser, $dbPwd);
mysql_select_db($dbName, $db);$newsRs = mysql_query("select news_id, title, release_date, release_time, base_path from " . $newsTable . " order by release_date desc, release_time desc" , $db);//获取新闻记录数
$cntRs = mysql_query("select count(*) from " . $newsTable );
$cntRow = mysql_fetch_row($cntRs);
$newsCount = $cntRow[0];
$pageCount = ceil($newsCount / $newsCountAPage);if($toPage > 1){
$firstRecordNumber = $newsCountAPage * ($toPage -1);
if($newsCount > $firstRecordNumber){
mysql_data_seek($newsRs, $firstRecordNumber);
}else{
//如果页数已经大于新闻的总页数,则退回到第一页
$toPage = 1;
}
}else{
$toPage = 1;
}
?>但是运行Index.aspx后却出现下列错误
--------------------------------------------------------------------------
PHP Warning: Undefined variable: dbHost1 in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbUser1 in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbPwd1 in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbName1 in D:\webs\xyw\CN\news\index.php on line 6 PHP Warning: Undefined variable: newsTable in D:\webs\xyw\CN\news\index.php on line 8 PHP Warning: Undefined variable: newsTable in D:\webs\xyw\CN\news\index.php on line 11
1。Common.php,代码是:
<?php
$fileSystemDec = "/";
$newsDocRootURL = ".." . $fileSystemDec . ".." . $fileSystemDec . "news" . $fileSystemDec . "news";
$dbHost = "localhost";
$dbName = "fudandb";
$dbUser = "root";
$dbPwd = "";
$applicationRootPath = "/cn";
$imagePath = $applicationRootPath . "/action/Images";
$CSSFile = $applicationRootPath . "/style.css";$insertImageTag = "<images/>";
$insertContentTag = "<news_content/>";
$insertTitleTag = "<title/>";
$insertDateTag = "<date/>";$newsCountAPage = 7;$newsTable = "news";
?>2。index.php 部分代码是:<? include("include/common.php") ?>
<? include("include/commonfunction.php") ?>
<?php
$db = mysql_connect($dbHost, $dbUser, $dbPwd);
mysql_select_db($dbName, $db);$newsRs = mysql_query("select news_id, title, release_date, release_time, base_path from " . $newsTable . " order by release_date desc, release_time desc" , $db);//获取新闻记录数
$cntRs = mysql_query("select count(*) from " . $newsTable );
$cntRow = mysql_fetch_row($cntRs);
$newsCount = $cntRow[0];
$pageCount = ceil($newsCount / $newsCountAPage);if($toPage > 1){
$firstRecordNumber = $newsCountAPage * ($toPage -1);
if($newsCount > $firstRecordNumber){
mysql_data_seek($newsRs, $firstRecordNumber);
}else{
//如果页数已经大于新闻的总页数,则退回到第一页
$toPage = 1;
}
}else{
$toPage = 1;
}
?>但是运行Index.aspx后却出现下列错误
--------------------------------------------------------------------------
PHP Warning: Undefined variable: dbHost1 in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbUser1 in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbPwd1 in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbName1 in D:\webs\xyw\CN\news\index.php on line 6 PHP Warning: Undefined variable: newsTable in D:\webs\xyw\CN\news\index.php on line 8 PHP Warning: Undefined variable: newsTable in D:\webs\xyw\CN\news\index.php on line 11
PHP Warning: Undefined variable: dbHost in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbUser in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbPwd in D:\webs\xyw\CN\news\index.php on line 5 PHP Warning: Undefined variable: dbName in D:\webs\xyw\CN\news\index.php on line 6 PHP Warning: Undefined variable: newsTable in D:\webs\xyw\CN\news\index.php on line 8 PHP Warning: Undefined variable: newsTable in D:\webs\xyw\CN\news\index.php on line 11
<? include("include/commonfunction.php"); ?>
据说在php5上要加上分号
因为PHP是弱类型语言,变量不需要定义拿来可以直接用,你可以在你的程序开始处加上error_reporting(E_ERROR | E_WARNING | E_PARSE);就不会提示变量没定义了!