简体   繁体   中英

LAMP Stack - 404 not found - 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

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).

You need to change the form action to following

 <!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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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