Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP不工作_Php_Html - Fatal编程技术网

PHP不工作

PHP不工作,php,html,Php,Html,这是一个send.php文件,我希望它采用通过表单提交的$givenRating,除以对该人进行评分的人数($numberOfRatings),然后在四舍五入后将该数据发送到文本文件。然而,所有发生的事情就是表单框中输入的数字被添加到他们的评级中 $givenRating = $_POST['rating']; /* Works */ $teacher1 = $_GET['teacher1'];/* Works */ $teacherRating = file_get_

这是一个send.php文件,我希望它采用通过表单提交的
$givenRating
,除以对该人进行评分的人数(
$numberOfRatings
),然后在四舍五入后将该数据发送到文本文件。然而,所有发生的事情就是表单框中输入的数字被添加到他们的评级中

$givenRating     = $_POST['rating']; /* Works */
$teacher1        = $_GET['teacher1'];/* Works */
$teacherRating   = file_get_contents("../game/teacher-profiles/" 
                                      . $teacher1 . "/rating.txt"); /* Works */
$numberOfRatings = file_get_contents("../game/teacher-profiles/" 
                                      . $teacher1 . "/ratings.txt"); /* Works */
settype($teacherRating,   "integer"); 
settype($numberOfRatings, "integer");
settype($givenRating,     "integer");

$finalRating     = $givenRating / $numberOfRatings;

if($finalRating > $teacherRating) {
    $send_rating = $teacherRating + $finalRating;
}
if($finalRating < $teacherRating) {
    $send_rating = $teacherRating - $finalRating;
}

$send_rating     = round($send_rating); 
$file            = fopen("../game/teacher-profiles/" 
                          . $teacher1 . "/rating.txt", "w") 
                          or die("Unable to open file!");

fwrite($file, $send_rating);
$givenRating=$_POST['rating'];/*工作*/
$teacher1=$_GET['teacher1'];/*工作*/
$teacherRating=文件\u获取\u内容(“../game/teacher profiles/”
.$teacher1.“/rating.txt”);/*工作*/
$numberOfRatings=文件获取内容(“../game/teacher profiles/”
.$teacher1.“/ratings.txt”);/*工作*/
settype($teacherRating,“integer”);
settype($numberOfRatings,“整数”);
settype($givenRating,“integer”);
$finalRating=$givenRating/$numberOfRatings;
如果($finalRating>$teacherRating){
$send_rating=$teacherRating+$finalRating;
}
如果($finalRating<$teacherRating){
$send_rating=$teacherRating-$finalRating;
}
$send_rating=圆形($send_rating);
$file=fopen(../game/teacher profiles/)
.$teacher1.“/rating.txt”,“w”)
或者死亡(“无法打开文件!”);
fwrite($file,$send_评级);

再次检查传递到
文件\u get\u contents()
方法的字符串
(路径)
,该方法用于代码中的
$teacherRating
$numberOfRatings
。他们似乎完全一样。其次,在任何算术运算中使用某些值之前,可能需要将字符串中的某些值显式转换为整数值或浮点值。请参阅下面的代码片段--

似乎与此非常相似,您不同意吗?似乎每个文件都写“2”?同样感谢您的警告,但是这些文件实际上是不同的
rating.txt
是评分,
ratings.txt
是对该教师评分的人数
<?php
    $givenRating     = isset($_POST['rating'])  ? intval(trim($_POST['rating']))  : 0;
    $teacher1        = isset($_GET['teacher1']) ? trim($_GET['teacher1'])         : '';
    $tRatingFile     = "../game/teacher-profiles/". $teacher1 . "/rating.txt";
    $numRatingFile   = "../game/teacher-profiles/". $teacher1 . "/ratings.txt";

    // NOTICE/WARNING: THE $tRatingFile & THE $numRatingFile ARE THE SAME
    // IS THIS CORRECT? COMPARE WITH YOUR ORIGINAL POST...
    $teacherRating   = ($data = file_get_contents($tRatingFile))   ? floatval($data) : 0;
    $numberOfRatings = ($data = file_get_contents($numRatingFile)) ? floatval($data) : 0;
    $send_rating     = 0;    //<== INITIALIZE $send_rating TO ZERO: 0

    /*********************************************/
    /*** UNNECESSARY BLOCK: SEE intval() ABOVE ***/
    /*********************************************/
    /*--------------------------------------------
    | settype($teacherRating,   "integer");      |
    | settype($numberOfRatings, "integer");      |
    | settype($givenRating,     "integer");      |
    ---------------------------------------------*/

    $finalRating     = $givenRating/$numberOfRatings;

    if($finalRating > $teacherRating) {
        $send_rating = $teacherRating + $finalRating;
    }
    if($finalRating < $teacherRating) {
        $send_rating = $teacherRating - $finalRating;
    }

    $send_rating     = round($send_rating);
    $file            = fopen($tRatingFile, "w") or die("Unable to open file!");

    fwrite($file, $send_rating);