繁体   English   中英

LAMP堆栈-找不到404-PHP

[英]LAMP Stack - 404 not found - PHP

您好我正在尝试配置LAMP堆栈

CentOS 7 Apache MariaDB PHP

我已经安装了所有内容并配置了虚拟主机和文件夹。

为了测试,我有一个域。 example.com

/var/www/example.com/public_html我有两个文件。

Index.html(基本页面)

<!DOCTYPE HTML PUBLIC>
<html>
 <body>

 <form action="/var/www/example.com/public_html/info.php" method="POST">

     Department: <input type="text" name="department"><br><br>
     Subname: <input type="text" name="Subname"><br><br>
     lables: <input type="text" name="lables"><br><br>
     pagerduty: <input type="text" name="pagerduty"><br><br>
     description: <input type="text" name="description"><br><br>


     <input type="submit" value="Submit" name="submit">

 </form>

</body>
</html>

info.php(表单处理程序)

<?php
$hostname = "localhost";
$username = "root";
$password = "xxxxxxxxx";
$db = "dora";
$dbconnect=mysqli_connect($hostname,$username,$password,$db);
if ($dbconnect->connect_error) {
 die("Database connection failed: " . $dbconnect->connect_error);
}
if(isset($_POST['submit'])) {
 $department=$_POST['department'];
 $subname=$_POST['subname'];
 $lables=$_POST['lables'];
 $pagerduty=$_POST['pagerduty'];
 $description=$_POST['description'];
$query = "INSERT INTO dora (department, subname, lables, pagerduty, description)
VALUES ('$department', '$subname', '$lables', '$pagerduty', '$description')";
if (!mysqli_query($dbconnect, $query)) {
      die('An error occurred when submitting your review.');
  } else {
    echo "Thanks for your review.";
  }
  }
?>

转到http:// localhost:80-加载我的index.html页面

转到http:// localhost:80 / info.php-加载PHP屏幕

我的问题是,当我填写表单并单击提交时,出现404错误,无法找到info.php

我是否缺少任何内容,所有内容看起来都应该可以使用所有权限等。

这是我第一次这样做,但是我很好地遵循了说明……任何指针都很棒。

非常感谢

您的表单操作指向磁盘上的位置,而不是相对于公用HTML文件夹的位置。

更改此:

<form action="/var/www/example.com/public_html/info.php" method="POST">

对此:

<form action="info.php" method="POST">

另外,请记住,您的代码库容易受到SQL注入的影响(例如,请尝试在表单输入之一中添加单引号)。

您需要将表单操作更改为以下内容

 <!DOCTYPE HTML PUBLIC>
 <html> 
<body> 
<form action="info.php" method="POST"> Department: <input type="text" name="department"><br><br> Subname: <input type="text" name="Subname"><br><br> lables: <input type="text" name="lables"><br><br> pagerduty: <input type="text" name="pagerduty"><br><br> description: <input type="text" name="description"><br><br> 
<input type="submit" value="Submit" name="submit"> </form> </body> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM