PHP 删除脚本仅适用于本地,不适用于远程 [英] PHP delete script works only on local, and not on remote

查看:60
本文介绍了PHP 删除脚本仅适用于本地,不适用于远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建一个网站,目的是学习php,本地开发网站,然后转移到远程.根目录中的一个文件夹是clients",它包含用于从表单中列出、插入、更新和删除客户反馈的脚本.在本地(XAMPP)所有脚本都可以完美运行.但是当我将它传输到远程时,一切正常,除了删除脚本.当我尝试删除遥控器上的条目时,它只会给出一个找不到页面的错误.我已附上相关代码如下.我将不胜感激.1. 下面是删除脚本的页面.

I am building a website for the purpose of learning php, developing website locally and then transferring to remote. One of the folders in root is 'clients', which consists of scripts to list, insert, update and delete client feedback from a form. Locally (XAMPP) all the scripts work perfectly. But when I transfer it to remote, everything works fine, EXCEPT for the delete script. When I try to delete the entries on remote, it simply gives a page not found error. I have attached the relevant codes as below. I would be grateful for assistance. 1. Below is the page with the delete script.

<?php require_once('scripts/db_delete_feedback.php'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delete Feedback</title>
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Delete Feedback</h1>
<p><a href="index.php">Admin menu</a></p>
<p>Please confirm that you want to delete the following record. This cannot be undone.</p>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>.">
<p><strong>Client Name:</strong><?php echo $feedback['name']; ?></p>
<p><strong>Feedback summary:</strong><?php echo $feedback['punch']; ?></p>
<p><strong>Rating:</strong><?php echo $feedback['rating']; ?></p>
<?php if ($photos) { ?>
<p>The following photos are linked with this client feedback. Select the checkbox next to each photo you want to delete at the same time as this feedback. To delete images without deleting the feedback, use <a href="list_photos.php">photo management page</a>.</p>
<table width="600">
<?php
$num = 0;
foreach ($photos as $photo) { ?>
  <tr>
    <td><input type="checkbox" name="photo[]" id="photo<?php echo $num;?>" value="<?php echo $photo['filename']; ?>" />
      <label for="photo<?php echo $num++; ?>" class="checkbox_label">Delete photo</label></td>
    <td><img src="../images/<?php echo $photo['filename']; ?>" width="200" alt="" /><br /><?php echo $photo['caption']; ?></td>
    </tr>
    <?php } ?>
</table>
<?php } ?>
<p>
  <input type="submit" name="delete_feedback" id="delete_feedback" value="Confirm Deletion" />
  <input type="submit" name="cancel" id="cancel" value="Cancel" />
  <input name="returnto" type="hidden" id="returnto" value="<?php echo $returnto; ?>" />
  <input name="client_id" type="hidden" id="client_id" value="<?php echo $client_id; ?>" />
</p>
</form>
</body>
</html>

  1. 以下是上述脚本中包含的db_delete_feedback.php"文件:

  1. Below is the 'db_delete_feedback.php' file included by the above script:

    <?php
$errors = array();
require_once('library.php');
try {
  require_once('db_definitions.php');
  $client_id = checkId('client_id', 'list_feedback.php');
  if (isset($_POST['delete_feedback'])) {
    // delete and redirect
    $dbWrite->delete('clients', "client_id = $client_id");
  $dbWrite->delete('client2photo', "client_id = $client_id");
  if (isset($_POST['photo'])) {
    foreach ($_POST['photo'] as $filename) {
      $dbWrite->delete('photos', "filename = '$filename'");
      unlink($destination . '/' . $filename);
    }
  }
  header('Location: ' . $_POST['returnto']);
  exit;
  }  elseif (isset($_POST['cancel'])) {
    header('Location: ' . $_POST['returnto']);
    exit;
  }
  $feedback = getFeedback($dbRead, $client_id);
  $photos = getRelatedPhotos($dbRead, $client_id);
  if (isset($_SERVER['HTTP_REFERER'])) {
    $returnto = $_SERVER['HTTP_REFERER'];
  } else {
    $returnto = 'list_feedback.php';
  }
} catch (Exception $e) {
  echo $e->getMessage();
}

包含的 library.php 文件包含 zend 框架库的路径.请帮助,因为我无法找到此问题的原因.

The included library.php file contains the path to zend framework library. Please help as I am unable to find the cause of this issue.

推荐答案

终于找到原因了.这是一个愚蠢的编码错误.额外的 .在表单操作中

Finally, I found the cause. It was a silly coding error. The extra . in the form action

这不适用于远程服务器,但适用于本地:

This doesn't work on the remote server, but works on Local:

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>.">

这适用于远程服务器:

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

这篇关于PHP 删除脚本仅适用于本地,不适用于远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆