开发者

I moved my PHP file to a subfolder and it's not working anymore

开发者 https://www.devze.com 2023-02-16 03:44 出处:网络
Below is a document tree of the folders on my website. In my html form the action attribute holds this value: delete_post.php. When I changed the action to /do/delete_post/index.php it wouldn\'t work.

Below is a document tree of the folders on my website. In my html form the action attribute holds this value: delete_post.php. When I changed the action to /do/delete_post/index.php it wouldn't work. How could I change this: do/delete_post/index.php or something else to make it work?

I moved my PHP file to a subfolder and it's not working anymore

The index.php file is shown below:

<?php
session_start();
if (!isset($_SESSION['user']) || empty($_POST['id'])) 
  {
  header( "Location: /" );
  die();
  }
require_once( dirname(__FILE__) . '/includes/db.php')
$stmt2 = $db->prepare('DELETE FROM posts W开发者_如何学运维HERE id = ?');
if (!$stmt2->execute(array($_POST['id'])))
  {
  print_r($stmt2->errorInfo());
  die();
  }
header( "Location: /" );

?>

When I make an ajax request using jquery in php with the following page the index.php fails to delete the post.


can you navigate to /do/delete_post/index.php without any errors (visible or in php error_log)?

i suspect either:

include_path issues

-or-

some url rewriting with .htaccess. is there a .htaccess file in the root dir?


Do you include any files within your workflow?

If you use relative paths, they are always relative to the current working directory (CWD) which is usually the directory where your executing script is.

If you change delete_post.php's folder and you are including a script which includes other scripts with relative paths, these scripts will fail to load as the CWD will be different.

So, instead of using relative paths, use the following:

include dirname(__FILE__) . '/data.inc.php';
0

精彩评论

暂无评论...
验证码 换一张
取 消