我无法解决为什么本地工作在主机服务器上失败的原因。它连接到数据库,检索和显示数据,但无法检索数据并包含表单。希望我已经包含了足够的代码。
首先检索并显示数据:
find /PATH/TO/FILES -type f -mmin +15 -exec rm -f {} +
然后,在用户希望编辑的行中,他单击编辑按钮。这是html:
/*------------------- DISPLAY ACCESSORIES ------------------*/
if(isset($_GET['table']) && $_GET['table'] === "accessories")
{
$table = 'accessories';
include '../includes/dbconnect.php';
try {
$result = $db->query("SELECT * FROM $table");
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$accessories[] = array(
'id' => $row['id'],
'buy_link' => $row['buy_link'],
'img' => $row['img'],
'item_number' => $row['item_number'],
'name' => $row['name'],
'description' => $row['description'],
'laser_series' => $row['laser_series'],
'laser_model' => $row['laser_model'],
'quantity' => $row['quantity'],
'price' => $row['price'],
);
}
}
catch (PDOException $e)
{
$error = 'Error fetching data.' . $e->getMessage();
include 'error.html.php';
exit();
}
try {
$sql2 = 'DESCRIBE accessories';
$s2= $db->prepare($sql2);
$s2->execute();
$table_fields = $s2->fetchAll(PDO::FETCH_COLUMN);
}
catch (PDOException $e)
{
$error = 'Error fetching data from database.';
include 'error.html.php';
exit();
}
// Close database connection
$db = null;
// Display data on included page
include 'display-accessories.html.php';
exit();
}
单击编辑按钮会触发此php,它会失败(不在本地)。它不包含文件(路径正确;在同一文件夹中)。
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<input type="hidden" name="id" value="<?php htmlout($accessory['id']); ?>">
<button class="btn btn-default btn-sm" type="submit" name="action" value="edit_accessories">Edit</button>
</form>
如果有人有任何想法,为什么这不起作用,我欢迎您的见解!
答案 0 :(得分:1)
只需更改句子:
FROM:'../ includes / dbconnect.php';
TO:$ _SERVER ['DOCUMENT_ROOT']。'/ includes / dbconnect.php';
在服务器中,路径不能写为'../',因为存在完全不同的服务器路径配置。