duan198123 2016-10-14 07:43
浏览 201
已采纳

PHP 7.0.10 - $ _Post无法使用

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.

  • 写回答

1条回答 默认 最新

  • doudao9915 2016-10-14 08:02
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口