I have spent 1 week on the question. I would like to save data from inputs inside a database MySQL with PHP. It's really easy I guess. I already made it 2-3 years ago but now there are a problem with PHP Version. During my research, I have found a lot of people with the same problem but without solution. At the beginning I work on PHP 5.6 and I had the HTTP_RAW_DATA_POST error. I decide to take all my project on PHP 7.0.10. It's looks like that :
My Form
echo "<form action='php/messageManagement.php' method='post'>";
echo "Titre : <input type='text' style='font-size: small;' name='titre'/><br>";
echo "Contenu : <input type='text' style='font-size: small;' name='contenu'/><br>";
echo "Auteur : <input type='text' style='font-size: small;' name='auteur'/><br>";
echo "<input type='submit'/>";
echo "</form>";
My PHP
<?php
try {
$bdd = new PDO('mysql:host=localhost;dbname=mojuwebsite;charset=utf8', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$titre = $_POST['titre'];
$contenu = $_POST['contenu'];
$auteur = $_POST['auteur'];
$parution = date("Y-m-d");
var_dump($titre);
$req = $bdd->prepare('INSERT INTO messages(titre, contenu, parution, auteur) VALUES (:titre, :contenu, :parution, :auteur');
$req->execute(array(
'titre' => $titre,
'contenu' => $contenu,
'parution' => $parution,
'auteur' => $auteur
));
$req->closecursor();
?>
Nothing complicate but my $_POST[] is always empty. In another forum where I check the problem, nobody has put a solution to this problem.
I'm not a professional PHP developpeur. Trust me I take time to make research and I'm really blocked. If you have a link who maybe could help me. Don't hesitate. Thank for your help.
ps : I have removed the Isset but it's change nothing. I guess I don't really need it.
First there is usually no Reason to write the POST variable $_POST['titre'] into $titre. Just be happy using the post variable directly (or even update it if you verify the inputs)
currently i assume it is a problem of the webserverconfiguration not php itself - as i tested using php 7.0.10 in a localserver mode:
C:\Programme\php7.10\php.exe -c "C:\Program Files\php7.10\php.ini-production" -S 127.0.0.1:80 -t D:\WWWROOT\tests
i get the result printed string(3) "abc"
when i type "abc" into Titre