Error messages

I'm a new beginner. Why are these error messages showing up? I need some assistance with this.

Warning: Undefined variable $totalNumber in C:\xampp\htdocs\Class\ch16\Johnson-calculating.php on line 76

Fatal error: Uncaught ArgumentCountError: fputs() expects at least 2 arguments, 1 given in C:\xampp\htdocs\Class\ch16\Johnson-calculating.php:80 Stack trace: #0 C:\xampp\htdocs\Class\ch16\Johnson-calculating.php(80): fputs('scores1.txt:81....') #1 {main} thrown in C:\xampp\htdocs\Class\ch16\Johnson-calculating.php on line 80

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//include functions from Johnson-inc-calc-functions.php file
		include ("Johnson-inc-calc-functions.php");

		// get the scores from the html file
		$fileName = $_POST['scores'];
		
		// Add the code which would read from a file called scoresFile
		// and input the score value into the array called scoresArray
		$scoresFile = fopen("$fileName", "r");
		$scores = fgets($scoresFile);
		while (!feof($scoresFile))
		{
			
			$scoresArray[] = floatval($scores);
			$scores = fgets($scoresFile);
		}
		fclose($scoresFile);
		
		// call each function and store in a new variable
		$average = avgArray($scoresArray);
		
		$highest = highestInArray($scoresArray);
			
		$lowest = lowestInArray($scoresArray);
		
		$numPassing = numPassingArray($scoresArray);
		
		$totalNumber = $totalNumber + sizeof($scoresArray);line 76
				
		$scoresFile = fopen("output.txt", "a");
		
		fputs("$fileName:$average:$highest:$lowest:$numPassing:$totalNumber\n");line 80
		
		fclose($scoresFile);  Put the code you need help with here.
What does the message say? Filter out the noise like filepaths and stack traces, and just look at the message itself:
fputs() expects at least 2 arguments, 1 given

So look up the documentation for the fputs function:
https://www.php.net/manual/en/function.fputs.php
fputs — Alias of fwrite()

Okay, so we actually need the documentation for fwrite.
https://www.php.net/manual/en/function.fwrite.php
fwrite ( resource $handle , string $string , int $length = ? ) : int

So the first argument of fputs needs to be the handle to the output you want to send it to. Perhaps a file, or STDOUT, or something like that.

PS: Your code is PHP, not C or C++. This is a C++ forum.
Last edited on
I say we merge the languages. We can call it PCP.
Thank you for your help and assistance with this.
Topic archived. No new replies allowed.