我是一名PHP程序员,我对下面的问题很困惑,我在等你的导游。 非常感谢! 有html代码
<form action="" method="POST">
<div>
<strong>Release: *</strong> <input type="text" name="Release" value="<?php echo $rel; ?>" /><br/>
<strong>User Story ID: *</strong> <input type="text" name="User Story ID" value="<?php echo $id; ?>" /><br/>
<strong>Test Owner *</strong> <input type="text" name="Test Owner" value="<?php echo $owner; ?>" /><br/>
<strong>Date of TC Review *</strong> <input type="text" name="Date of TC Review" value="<?php echo $data; ?>" /><br/>
<strong>By Design </strong> <input type="text" name="By Design" value="<?php echo $design; ?>" /><br/>
<strong>By Review </strong> <input type="text" name="By Review" value="<?php echo $review; ?>" /><br/>
<strong>By Defect </strong> <input type="text" name="By Defect" value="<?php echo $defect; ?>" /><br/>
<p>* required</p>
<input type="submit" name="submit" value="Submit">
</div>
</form>
有php代码
if (isset($_POST['submit']))
{
// get form data, making sure it is valid
$release = mysql_real_escape_string(htmlspecialchars($_POST['Release']));
// $ID = " abc";
echo $_POST['Release'];
echo $_POST['User Story ID'];
$ID = mysql_real_escape_string(htmlspecialchars($_POST["User Story ID"]));
$T_Owner = mysql_real_escape_string(htmlspecialchars($_POST['Test Owner']));
$data = mysql_real_escape_string(htmlspecialchars($_POST['Date of TC Review']));
$T_ByDesign= mysql_real_escape_string(htmlspecialchars($_POST['By Design']));
$T_ByReview= mysql_real_escape_string(htmlspecialchars($_POST['By Review']));
$T_ByDefect= mysql_real_escape_string(htmlspecialchars($_POST['By Defect']));
// check to make sure both fields are entered
if ($release == '' || $ID == ''||$T_Owner==''||$data=='')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
// if either field is blank, display the form again
renderForm($release, $ID, $T_Owner, $data, $T_ByDesign, $T_ByReview, $T_ByDefect, $error);
}
else
{
// save the data to the database
mysql_query("INSERT Tests SET T_Release='$release', ID='$ID',TestOwner='$T_Owner',T_Date='$data',Test_ByDesign='$T_ByDesign',Test_ByReview='$T_ByReview',Test_ByDefect='$T_ByDefect'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: view.php");
}
}
错误信息如下:
Notice: Undefined index: User Story ID in C:\xampp\htdocs\Test\new.php on line 47
abc
Notice: Undefined index: User Story ID in C:\xampp\htdocs\Test\new.php on line 55
Notice: Undefined index: User Story ID in C:\xampp\htdocs\Test\new.php on line 56
Notice: Undefined index: Test Owner in C:\xampp\htdocs\Test\new.php on line 57
Notice: Undefined index: Date of TC Review in C:\xampp\htdocs\Test\new.php on line 58
Notice: Undefined index: By Design in C:\xampp\htdocs\Test\new.php on line 59
Notice: Undefined index: By Review in C:\xampp\htdocs\Test\new.php on line 60
Notice: Undefined index: By Defect in C:\xampp\htdocs\Test\new.php on line 61
答案 0 :(得分:2)
您使用表单输入元素的无效名称。 不要在表单名称中包含空格。
答案 1 :(得分:2)
第1次编辑表单:
<form action="" method="POST">
<div>
<strong>Release: *</strong> <input type="text" name="Release" value="<?php echo $rel; ?>" /><br/>
<strong>User Story ID: *</strong> <input type="text" name="User_Story_ID" value="<?php echo $id; ?>" /><br/>
<strong>Test Owner *</strong> <input type="text" name="Test_Owner" value="<?php echo $owner; ?>" /><br/>
<strong>Date of TC Review *</strong> <input type="text" name="Date_of_TC_Review" value="<?php echo $data; ?>" /><br/>
<strong>By Design </strong> <input type="text" name="By_Design" value="<?php echo $design; ?>" /><br/>
<strong>By Review </strong> <input type="text" name="By_Review" value="<?php echo $review; ?>" /><br/>
<strong>By Defect </strong> <input type="text" name="By_Defect" value="<?php echo $defect; ?>" /><br/>
<p>* required</p>
<input type="submit" name="submit" value="Submit">
</div>
不要在表单名称上使用空格,那么你可以得到这样的帖子值:
if (isset($_POST['submit']))
{
// get form data, making sure it is valid
$release = mysql_real_escape_string(htmlspecialchars($_POST['Release']));
echo Print_r($_POST['Release']);
echo Print_r($_POST['User_Story_ID']);
$ID = $_POST["User_Story_ID"];
$T_Owner = $_POST['Test_Owner'];
$data = $_POST['Date_of_TC_Review'];
$T_ByDesign= $_POST['By_Design'];
$T_ByReview= $_POST['By_Review'];
$T_ByDefect= $_POST['By_Defect'];
// check to make sure both fields are entered
if ($release == '' || $ID == ''||$T_Owner==''||$data=='')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
// if either field is blank, display the form again
renderForm($release, $ID, $T_Owner, $data, $T_ByDesign, $T_ByReview, $T_ByDefect, $error);
}
else
{
// save the data to the database
mysql_query("INSERT Tests SET T_Release='$release', ID='$ID',TestOwner='$T_Owner',T_Date='$data',Test_ByDesign='$T_ByDesign',Test_ByReview='$T_ByReview',Test_ByDefect='$T_ByDefect'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: view.php");
}
答案 2 :(得分:1)
首先,永远不要在php或任何其他编程中使用“By Design”类型的编码而不是它,你应该像这样使用“By_Design”或使用cameCaps(byDesign)。什么是你的html表单中的$ rel,$ id和其他东西,你没有提到它。导致问题的主要问题是在表单和php中使用空格。请不要使用它。
答案 3 :(得分:1)
我尝试了一些测试代码:
<form action="" method="POST">
<input type="submit" name="what happened" value="here" />
</form>
<?php
print_r($_POST);
?>
似乎PHP将名称中带有空格的所有元素替换为下划线。因此,您希望使用$_POST['User_Story_ID']
代替$_POST['User Story ID']
。等
答案 4 :(得分:0)
添加表单操作&#34; your_page.php
&#34;
示例:<form action="your_page.php" method="POST">
并删除表单输入元素的空间,如:
echo $_POST['User Story ID'];
而不是:
示例:
<strong>User Story ID: *</strong> <input type="text" name="UserStoryID" value="<?php echo $id; ?>" /><br/>
echo $_POST['UserStoryID'];
或您想要命名的任何内容
答案 5 :(得分:0)
您应该在使用前定义变量。请再来一次。