Php 在表单提交时运行脚本

Php 在表单提交时运行脚本,php,forms,execute,Php,Forms,Execute,我一直在四处寻找这个问题,我真的很困惑,有类似的问题,但我似乎无法使任何一个工作。因此,如果之前有人重复这一点,我深表歉意。这是我的问题,我需要在表单提交上运行php脚本,而不是重新定向到该页面。这是我的密码: 表格: Comments.php: <?php $fileNameHere = 'filenamehere.php'; $hits[0] ++; $fileNameHereFileHandle = fopen($fileNameHere, 'a+

我一直在四处寻找这个问题,我真的很困惑,有类似的问题,但我似乎无法使任何一个工作。因此,如果之前有人重复这一点,我深表歉意。这是我的问题,我需要在表单提交上运行php脚本,而不是重新定向到该页面。这是我的密码: 表格:


Comments.php:

<?php   
    $fileNameHere = 'filenamehere.php';
    $hits[0] ++;

    $fileNameHereFileHandle = fopen($fileNameHere, 'a+') or die("can't open file");
    $subjectField = $_POST['subjectField'];
    $messageField = $_POST['messageField'];
    $savestring = '' . $hits[0] .'';
    fputs($fileNameHereFileHandle, $savestring);
    fclose($fileNameHereFileHandle);
?>

这样做的好处是什么?如果你想在不重载页面的情况下提交数据,那么你应该考虑使用jQuery和Ajax来代替。你正在寻找一种运行服务器端代码的方法,而不用离开你正在使用的页面。如果你把评论文件放在同一个页面上,然后删除这个动作,它应该发布到同一个页面。非常感谢,很抱歉造成混淆:)代码现在没有意义,我还在学习:)
<?php   
    $fileNameHere = 'filenamehere.php';
    $hits[0] ++;

    $fileNameHereFileHandle = fopen($fileNameHere, 'a+') or die("can't open file");
    $subjectField = $_POST['subjectField'];
    $messageField = $_POST['messageField'];
    $savestring = '' . $hits[0] .'';
    fputs($fileNameHereFileHandle, $savestring);
    fclose($fileNameHereFileHandle);
?>