php 注意:未定义索引:id in C:\xampp\htdocs\

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14673457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:45:57  来源:igfitidea点击:

Notice: Undefined index: id in C:\xampp\htdocs\

phpindexingundefined

提问by Wong Jia Min Jacey

Possible Duplicate:
Reference - What does this error mean in PHP?

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

I am trying to establish a database using PHP but I keep getting errors saying I have an undefined index in id.

我正在尝试使用 PHP 建立一个数据库,但我不断收到错误消息,说我在 id 中有一个未定义的索引。

I want to add data into my database, also able to update, delete and show the infomation. This is my update info codes.

我想将数据添加到我的数据库中,还可以更新、删除和显示信息。这是我的更新信息代码。

<?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.';
}

?>

回答by EM-Creations

It sounds like $_POST['id']isn't being set.

好像$_POST['id']没有设置

You need to make sure it's being set before using it, or check if it's set and give it a default value if it isn't.

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

Eg:

例如:

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;
}

回答by mvbrakel

The following line will most likelt cause it:

以下行最有可能导致它:

$dmdid=$_POST['id'];

Verify your form (or other POST supplier) provides the 'id' key. with something like:

验证您的表单(或其他 POST 供应商)提供了“id”键。像这样:

<input type="hidden" name="id"  value="xx"/>