在我编写的代码中,我在135-154行得到了多个未定义的索引错误...我很确定我已经在第125-130行定义了必要的变量。我已经检查了与此问题有关的其他问题,但我找不到任何相关信息。任何人都可以解释为什么我仍然得到这个错误,即使我定义了这些变量?非常感谢任何帮助。
编辑:我得到的错误信息是:注意:未定义的索引: 第133行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php中的语法
注意:未定义的索引:读入 第134行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php
注意:未定义的索引:写入 第135行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php
注意:未定义的索引:收听 第136行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php
注意:未定义的索引:说话 第137行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php
注意:未定义的索引:评估在 第138行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php
注意:未定义的变量:评估中 第150行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php
注意:未定义的索引:进度 第152行的C:\ xamppnew \ htdocs \ loginSignup \ teachersPage.php
<?php require_once('Connections/connection.php'); ?>
<?php
session_start(); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "TestResults")) {
$insertSQL = sprintf("INSERT INTO test_results (gt, grammar, Fname, Lname, reading, writing, speaking, listening, overall) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['gt'], "int"),
GetSQLValueString($_POST['grammar'], "text"),
GetSQLValueString($_POST['Fname'], "text"),
GetSQLValueString($_POST['Lname'], "text"),
GetSQLValueString($_POST['reading'], "text"),
GetSQLValueString($_POST['writing'], "text"),
GetSQLValueString($_POST['speaking'], "int"),
GetSQLValueString($_POST['listening'], "int"),
GetSQLValueString($_POST['overall'], "int"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
}
mysql_select_db($database_connection, $connection);
$query_Recordset1 = "SELECT * FROM test_results";
$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_connection, $connection);
$query_Recordset2 = "SELECT * FROM test_results";
$Recordset2 = mysql_query($query_Recordset2, $connection) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$query_Recordset1 = "SELECT * FROM test_results";
$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Teacher's Page</title>
<link href="insert.php" rel="stylesheet" type="text/php"/>
<link href="ssmenu.css" rel="stylesheet" type="text/css"/>
<link href="sslayout.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
.boxed {
margin: auto;
padding: 2px;
height: auto;
width: 160px;
border: medium solid #000;
font-size: 20px;
}
.boxed1 {
margin: auto;
padding: 2px;
height: 750px;
width: 700px;
border: medium solid #000;
font-size: 17px;
}
.boxed2 {
margin: auto;
padding: 2px;
height: auto;
width: 500px;
border: medium solid #000;
font-size: 20px;
}
</style>
<link href="fpdf.php"
</head>
<body>
<h1 align="center">
<style type="text/css">
#NavBar nav .form #form1 .form tr td {
color: #FFF;
}
</style>
<p align="center" class="boxed"><strong>EACAD003 – I1</strong></p>
<?php
$grammar = $row_Recordset1['grammar'];
$reading = $row_Recordset1["reading"];
$writing = $row_Recordset1["writing"];
$listening = $row_Recordset1["listening"];
$speaking = $row_Recordset1["speaking"];
$assesment = $row_Recordset1["assesment"];
?>
<?php
$_SESSION["grammar"] = $_POST["grammar"];
$_SESSION["reading"] = $_POST["reading"];
$_SESSION["writing"] = $_POST["writing"];
$_SESSION["listening"] = $_POST["listening"];
$_SESSION["speaking"] = $_POST["speaking"];
$_SESSION["assessment"] = $_POST["assessment"];
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$grammar = $_POST['Grammar'];
$reading = $_POST['Reading'];
$writing = $_POST['Writing'];
$listening = $_POST['Listening'];
$speaking= $_POST['Speaking'];
$assessment= $_POST['assessment'];
}
$Results = $grammar + $reading + $writing + $listening + $speaking + $assessment;
$Overall = $Results/100;
$checkBox = implode(',', $_POST['Progress']);
if(isset($_POST['SubmitForm']))
{
$query="INSERT INTO test_results (Grammar, Reading, Writing, Listening, Speaking, Assesment, Progress) VALUES ('$Grammar','$Reading','$Writing','$Listening','$Speaking','$assessment','" . $checkBox . "')";
?>
<form action="<?php echo $editFormAction; ?>" method="post" name="TestResults" class="boxed1" id="TestResults">
<p> </p>
<div class="boxed2">
<h3 align="center">ELIT LANGUAGE CENTRE </h3>
<h3 align="center">TEST RESULTS </h3>
<p align="center">
<select name="ClassLevel" id="ClassLevel">
<option value="Elementary 1" <?php if (!(strcmp("Elementary 1", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Elementary 1</option>
<option value="Elementary 2" <?php if (!(strcmp("Elementary 2", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Elementary 2</option>
<option value="Elementary 3" <?php if (!(strcmp("Elementary 3", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Elementary 3</option>
<option value="Intermediate 1" <?php if (!(strcmp("Intermediate 1", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Intermediate 1</option>
<option value="Intermediate 2" <?php if (!(strcmp("Intermediate 2", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Intermediate 2</option>
<option value="Intermediate 3" <?php if (!(strcmp("Intermediate 3", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Intermediate 3</option>
<option value="Pre-Intermediate 1" <?php if (!(strcmp("Pre-Intermediate 1", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Pre-Intermediate 1</option>
<option value="Pre-Intermediate 2" <?php if (!(strcmp("Pre-Intermediate 2", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Pre-Intermediate 2</option>
<option value="Pre-Intermediate 3" <?php if (!(strcmp("Pre-Intermediate 3", $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>>Pre-Intermediate 3</option>
<option value="<?php echo $row_Recordset1['ClassLevel']?>"<?php if (!(strcmp($row_Recordset1['ClassLevel'], $row_Recordset1['ClassLevel']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset1['ClassLevel']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</p>
</div>
<table width="632" border="0" align="center">
<tr>
<td width="163">First Name</td>
<td width="260"><label for="Fname"></label>
<input name="Fname" type="text" id="Fname" /></td>
<td width="195"><label for="Lname"></label></td>
</tr>
<tr>
<td>Last Name</td>
<td><label for="gt"></label>
<input name="Lname" type="text" id="Lname" /></td>
<td> </td>
</tr>
<tr>
<td>Passport No.</td>
<td><label for="date">
<input name="gt" type="text" id="gt" />
</label></td>
<td> </td>
</tr>
<tr>
<td>Date:</td>
<td><label for="teacher_name">
<input type="text" name="date" id="date" />
</label></td>
<td> </td>
</tr>
<tr>
<td>Teacher:</td>
<td><input type="text" name="teacher_name" id="teacher_name" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><label for="grammar"></label></td>
<td> </td>
</tr>
<tr>
<td>Grammar:</td>
<td><label for="grammar"></label>
<input name="grammar" type="text" id="grammar" /> <strong>/35</strong></td>
<td> </td>
</tr>
<tr>
<td>Reading:</td>
<td><label for="reading"></label>
<input name="reading" type="text" id="reading" />
<strong>/20</strong></td>
<td> </td>
</tr>
<tr>
<td>Writing</td>
<td><label for="writing">
<input name="writing" type="text" id="writing" />
<strong>/20</strong></label></td>
<td> </td>
</tr>
<tr>
<td>Listening:</td>
<td><label for="listening"></label>
<input name="listening" type="text" id="listening" />
<strong>/20</strong></td>
<td> </td>
</tr>
<tr>
<td>Speaking</td>
<td><input name="speaking" type="text" id="speaking" />
<strong>/20</strong></td>
<td> </td>
</tr>
<tr>
<td>Teacher's Assesment:</td>
<td><label for="assesment"></label>
<input type="text" name="assesment" id="assesment" />
<strong>/15</strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><label for="textfield2"></label></td>
</tr>
<tr>
<td> </td>
<td><p>
<input name="overall" type="text" id="overall" value="<?php echo "$result" ?>"/>
<label for="overall"></label>
/130</p></td>
<td><p>
<input name="percentage" type="text" id="percentage" value="<?php echo "$Overall" ?>" />
%</p></td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="Calculate" id="Calculate" value="Calculate" /></td>
<td> </td>
</tr>
<tr>
<td>Teacher's Recommendation:</td>
<td>Repeat
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="TestResults" />
</form>
<form id="form1" name="form1" method="submit" action="">
<label for="ClassLevel"></label>
<input type="submit" name="SubmitForm " id="SubmitForm " value="Submit Grades" />
<br />
<p>
</p>
</body>
</html>
</td>
</form>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
答案 0 :(得分:0)
您的问题是使用非存在变量。
Ex:135-140行
$ _ POST不存在于initial =&gt;未定义的错误
修改代码如下: 在将其设置为值
之前确保变量存在$_SESSION["grammar"] = isset($_POST["grammar"]) ? $_POST["grammar"] : '';
http://php.net/manual/en/function.isset.php
希望对你有用!