I have an html form like this:
</div>
<form method="POST" action = "process.php">
<input type="text" name="user" placeholder="Enter your name"/>
<input type="text" class="message" name="message" placeholder="Enter your message"/>
<input type="submit" class="btn-default " name="submit" value="Shout it out"/>
</form>
</div>
After I press the button Shout it out
to submit it, my $_POST
array does not fill with any values while $_GET
is working fine.
var_dump($_POST);
this gives me array{0}
.
this is my process.php:
<?php
include 'database.php';
//Check if form submitted
if(isset($_POST['submit'])) {
$user = mysqli_real_escape_string($con, $_POST['user']);
$message = mysqli_real_escape_string($con, $_POST['message']);
// Set timezone
date_default_timezone_set('America/New_York');
$time = date('h:i:s a', time());
echo $time;
}
// Validate input
if (!isset($user) || $user == '' || !isset($message) || $message == '') {
echo 'bad';
var_dump($_POST);
} else {
echo 'good';
}
and this is the database.php:
<?php
$host = 'localhost';
$username ='root';
$password= '';
$db = "shoutit";
//Connection to the DB
$con = mysqli_connect("$host", "$username", "$password", "$db");
//Test and debugging
if(mysqli_connect_errno()) {
echo'Failed to connect to the database: '.mysqli_connect_errno();
}
?>
?>
What i have tried so far:
1.Modifying my php.ini
( both the 5.3 and 7.0 versions), more precisely, checking if post_max_size = 8M;
and upload_max_filesize = 2M;
(since some people, had a problem where their post_max_size was automatically changed to something like 60MB or so), this didn't work out.
2.Changing method="post"
to method="POST"
and vice versa.
3.Running through all( I should say mostly all of the other submitted tickets on Stack, except maybe those, where the problem was caused by JavaScript, this is not the case obviously).
4.I checked if my name in the form is the same Im using in my $_POST
and etc.
I Believe the problem might be caused, because I am using windows. One of my friends is using uBuntu, and he has no such problem, he gets the $_POST
array filled after submission.
Is there a way to solve it or I should go for Ubuntu straight away?
P.S I don't think this should be marked as a duplicate question, since it does not have an answer yet.(None of the previously submitted on stack do):
PHP $_POST not working but $_GET works fine
php $_POST array empty upon form submission
this is just a few that didn't work out.