dongluanban3536 2017-12-26 15:38
浏览 48
已采纳

LAMP堆栈 - 找不到404 - PHP

Hello I am trying to configure a LAMP stack

CentOS 7 Apache MariaDB PHP

I have installed everything and configured my virtual host and folders.

For testing I have a domain. example.com

in /var/www/example.com/public_html I have two files.

Index.html (Basic page)

<!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 (Form handler)

<?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.";
  }
  }
?>

Going to http://localhost:80 - Loads my index.html page

Going to http://localhost:80/info.php - Loads the PHP screen

My issue is when I complete the form and click submit, I get a 404 error where info.php cannot be found.

Am I missing something, everything looks like it should work all permissions etc.

This is my first time doing this but I followed the instructions well...any pointers would be great.

Many thanks

  • 写回答

2条回答 默认 最新

  • doulai8128 2017-12-26 15:42
    关注

    Your form action is pointing to a location on disk, not to a location relative to your public HTML folder.

    Change this:

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

    to this:

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

    Also please keep in mind that your codebase is vulnerable to SQL injection (as an example, try adding a single-quote to one of your form inputs).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?