我提交了一个HTML表单旁边的代码,一旦提交表单,php文件应该执行它的任务,但它只打印出屏幕上的实际php代码。我不确定它是否是形式值,或者我只是错过了简单的错误,但任何帮助都会非常感激。
我提交了一个HTML表单旁边的代码,一旦提交表单,php文件应该执行它的任务,但它只打印出屏幕上的实际php代码。我不确定它是否是形式值,或者我只是错过了简单的错误,但任何帮助都会非常感激
<?php
//linking table to form
$studentid=$_POST["id"];
//To print out student ID
echo "You have selected Student ID: $studentid <br />";
//define what the file equals to which is the students ID
$file = "$studentid.txt";
//Opening the selected files
$fileopen = fopen($file,'r') or die("Sorry, cannot open $file");
if($fileopen){
while (($buffer=fgets($fileopen,4096))!==false){
// echo $buffer."<br/>";
}
if(!feof($fileopen)){
echo "Error:unexpected fgets() fail\n";
}
fclose($fileopen);
}
//remove all commas from txt file
$filearray=file("$studentid.txt");
$count=count($filearray);
for($i=0; $i<$count; $i++){
$startnum=0;
$stringlength = strlen($filearray[$i]);
$comma = strpos($filearray[$i], ",", $startnum);
$array[$i][0] = substr($filearray[$i], $startnum, $comma);
$j=1;
while ($j<$count-1){
$comma = strpos($filearray[$i], ",", $startnum);
$comma2 = strpos($filearray[$i], ",", $comma+1);
$sub = $comma2-$comma;
$num = substr($filearray[$i], $comma+1, $sub -1);
$startnum = $comma2;
$array[$i][$j]= $num;
$j++;
}
$stop = $stringlength - $comma2;
$array[$i][$j] = substr ($filearray[$i], $comma2 + 1, $stop);
}
//table heading
echo"<h1>The Original Table</h1>";
//creating the rows and columns for the txt file
echo "<table border = 1 >";
for($row=0; $row<$count; $row++){
print "<tr>";
for($col=0; $col<$count; $col++){
print "<td>".$array[$row][$col]."</td>";
}
}
echo "</table>";
// transpose function
function transpose_matrix($a, $c){
//saving the new array
$t_arr = array();
//table heading
echo"<h1>Transpose Matrix</h1>";
//creating the rows and columns for the txt file
echo "<table border = 1 >";
for($row=0; $row<$c; $row++){
print "<tr>";
//saving the new array columns
$n_col=array();
for($col=0; $col<$c; $col++){
$t_arr[$col][$row] = $a[$col][$row]; //reversing the column and row to transpose the table
print "<td>".$a[$col][$row]."</td>";
}
}
echo "</table>";
return $t_arr;
}
$aa = transpose_matrix($array, $count);
echo "<h1>Sum Matrix</h1>";
function sum_matrix($arr, $co) {
$t_arr = array();
$s=0; //Declaring the total
echo "<table border = 1 >";
for ($row=0; $row< $co; $row++) {
print "<tr>";
for($col=0; $col<=$row; $col++) {
$s+= $arr[$col][$row]; //Adding the rows and columns in the new array
print "<td>".$arr[$col][$row]."</td>";
}
} echo "</table>";
return $s; //returning the total
}
$b= sum_matrix($array, $count); //assigning the result of the function into a new variable
echo "<br />The total sum of the lower diagonal in the array is ". $b;
?>