我想将用户值从 HTML 表单获取到数组,然后将其插入 mysql 数据库。它将正确的值插入数据库,然后给出以下错误:
注意:未定义索引:第 153 行 C:\wamp\www\Capturing System\All_Topics_widget.php 中的 TopicNum
以下内容位于页面顶部:
<?php
include 'scripts/functions/init.php';
Restrict();
?>
$userid = $_SESSION['userid'];
$KM_Number = $_SESSION['C_KM'];
$query = "SELECT * FROM knowledge_modules where km_number = "."'".$KM_Number."'";
$Knowledge = mysql_query($query) or die(mysql_error);
$row = mysql_fetch_assoc($Knowledge);
$Module_type = 'Knowledge Modules';
$Purpose_M = $_SESSION['Purpose_KM'];
$KM = 'KM';
$NUM = $_SESSION['KM'];
$KT = 'KT';
if (empty($_POST)=== false)
{
$R_fields = array('Topic_Num','Title','Weight');
foreach($_POST as $key=>$value)
{
if (empty($value) && in_array($key,$R_fields)=== true)
{
$errors[] = 'fields marked with (*) are required';
break 1;
}
}
if(empty($errors)=== true)
{
if(topic_exists($_POST['TopicNum']))
{
$errors[] = 'Sorry, the Topic already exist!';
}
}
}
?> 以下代码在 HTML 标签中:
<h2>Tools - </h2>
<form action="All_Topics_widget.php" method="POST" enctype="multipart/form-data">
<fieldset>
<table border="0">
<tr>
<td><label for="TopicNum">Topic Number:* <?php echo $KM.'-'.$NUM.'-'.$KT ?></label></td>
<td><input type="text" size="5" name="TopicNum" /></td>
</tr>
<tr>
<td><label for="Title">Title:*</label></td>
<td><input type="Text" size="35" name="Title"/></td>
</tr>
<tr>
<td><label for="Weight">Weight:*</label></td>
<td><input type="text" size="05" name="Weight" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<table border="0">
<tr>
<td><input id="Submit" type="submit" value="Capture" /></td>
<td><input id="Reset1" type="reset" value="reset" /></td>
<td><a href="list_topics.php">Capture Topics</a></td>
</tr>
</table>
</fieldset>
<?php
$Topics = $KM.'-'.$NUM.'-'.$KT.$_POST['TopicNum'];//This is line 153
if(isset($_GET['success']) && empty($_GET['success']))
{
echo 'Succefully Captured';
}
else
{
if(empty($_POST) == false && empty($errors)== true)
{
//Capture data from the fields to an array
$capture_topic = array(
'TopicNum' => $Topics,
'Title'=>$_POST['Title'],
'Weight'=>$_POST['Weight'],
'Purpose_M'=>$Purpose_M,
'userid'=>$userid);
//Submit the data into the database
capture_topic($capture_topic);
//redirect to the Modules widget page till the user press NEXT Page
header('Location: All_Topics_widget.php?success');
exit();
}
else if(empty($errors)== false)
{
//Display errors
echo output($errors);
}
}
?>
</form>