![](/img/trans.png)
[英]Why can't this function see the variables of a file included in an included file?
[英]can't find the xml file in the included file
文件夾層次結構為:
phpproject:
config.php
admin.xml
crimes:
addcrime.php
addcrime.php的內容是:
<?php
include("../config.php");
if (isset($_POST['submitted'])) {
foreach ($_POST AS $key => $value) {
$_POST[$key] = mysql_real_escape_string($value);
}
$sql = "INSERT INTO `crime` (`crime_name`,`crime_type` ) VALUES( '{$_POST['crime_name']}','{$_POST['crime_type']}' ) ";
mysql_query($sql) or die(mysql_error());
echo "Added row.<br />";
echo "<a href='list.php'>Back To Listing</a>";
}?>
犯罪名稱:
犯罪類型:
config.php的內容:
如果(file_exists(“ ./ admin.xml”)){
$xml = simplexml_load_file("./admin.xml");
$uid = trim($xml->name);
$pwd = trim($xml->password);
$db = trim($xml->dbname);
echo $uid;
echo $pwd;
$link = mysql_connect('localhost', $uid, $pwd);
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db($db, $link);
if (!$db_selected) {
die('Can\'t use : ' . $db . ' ' . mysql_error());
} else {
echo "<h2> Database " . $db . " selected successfully " . "</h2> <br/>";
echo "<h2> Username:" . $uid . "</h2> <br/>";
}
}其他{
echo "file not found";
}?>
config.php文件找不到同一文件夾中的admin.xml
本質上,@ CBroe在他的評論中說了什么。 您可能想嘗試的是:
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'admin.xml'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.