注意:未定义的索引:在C:\ xampp \ htdocs \

可能重复:
参考 - 这个错误在PHP中意味着什么?

我试图建立一个数据库使用PHP,但我不断收到错误,说我有一个未定义的索引在ID。

我想将数据添加到我的数据库中,也能够更新,删除和显示信息。 这是我的更新信息代码。

<?PHP
// Connection to MySQL
$dbconnection = @mysql_connect('localhost','root','');
if (!$dbconnection) {
echo '<p> Unable to connect to the database at this time.</br></br></p>';
exit();}
else {
echo '<p> connection to database is successful</br></br> </p>';}
//select Mysql Database-ijdb
if (!@mysql_select_db('disease')){
 exit('<p> Unable to locate the information on the database.</p>');
}

//Receive Variables from the GET of JOKELIST.php
if(isset($_POST['submit']))
{
$GeneticOrganisation=$_POST['newGeneticOrganisation'];
$ProteinInformation=$_POST['newProteinInformation'];
$Symptoms=$_POST['newSymptoms'];
$Population=$_POST['newPopulation'];
$Cure=$_POST['newCure'];
$OriginOfDisease=$_POST['newOriginOfDisease'];
$dmdid=$_POST['id'];
// Print receieved variables to check accuracy

 $sql= "UPDATE dmd SET GeneticOrganisation ='".$GeneticOrganisation."' WHERE id                
`='".$dmdid."'";
$sql= "UPDATE dmd SET ProteinInformation ='".$ProteinInformation."' WHERE id  ='".$dmdid."'";                                
 $sql= "UPDATE dmd SET Symptoms ='".$Symptoms."' WHERE id ='".$dmdid."'";
$sql= "UPDATE dmd SET Population ='".$Population."' WHERE id ='".$dmdid."'";
$sql= "UPDATE dmd SET Cure ='".$Cure."' WHERE id ='".$dmdid."'";
$sql= "UPDATE dmd SET OriginOfDisease ='".$OriginOfDisease."' WHERE id ='".$dmdid."'";
}
if (!@mysql_query($sql))
 echo "<p> Information could not be updated-".mysql_error();
 else{
echo "<p> Information updated successfully";
echo '<a href="diseaseInfo.php"> View the information on the disease here.';
}

?>

这听起来像$_POST['id']没有被设置。

在使用它之前,您需要确保它已被设置,或者检查它是否已设置,如果不是,则将其设置为默认值。

例如:

if (isset($_POST['id'])) { // If the id post variable is set
    $dmid = $_POST['id'];
} else { // If the id post variable is not set
    $dmid = 1;
}

以下几行将最有可能导致它:

$dmdid=$_POST['id'];

验证您的表单(或其他POST供应商)提供'id'键。 像这样的东西:

<input type="hidden" name="id"  value="xx"/>
链接地址: http://www.djcxy.com/p/69405.html

上一篇: Notice: Undefined index: id in C:\xampp\htdocs\

下一篇: String could not be parsed as XML