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 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 已知隐函数其中一个变量的,求另外一个变量
  • ¥15 echarts图表制作
  • ¥15 halcon根据玻璃面板纹路取区域
  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究
  • ¥15 微服务假死,一段时间后自动恢复,如何排查处理