-1

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

I am trying to establish a database using PHP but I keep getting errors saying I have an undefined index in 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.';
}

?>
Community
  • 1
  • 1
  • 5
    Please, don't use `mysql_*` functions to write new code. They are no longer maintained and the community has begun [deprecation process](http://goo.gl/q0gwD). See the [red box](http://goo.gl/OWwr2)? Instead you should learn about [prepared statements](http://goo.gl/orrj0) and use either [PDO](http://goo.gl/TD3xh) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://goo.gl/YXyWL) will help you. If you pick PDO, [here is good tutorial](http://goo.gl/b2ATO). Also see [Why shouldn't I use mysql functions in PHP?](http://goo.gl/J5jAo) – DCoder Feb 03 '13 at 14:25
  • 1
    @DCoder They are now fully deprecated. You can update your boilerplate from [this answer](http://stackoverflow.com/a/12860140/64976), which I find immensely useful. =) – J. Steen Feb 03 '13 at 14:41

2 Answers2

4

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

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;
}
EM-Creations
  • 4,195
  • 4
  • 40
  • 56
0

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:

<input type="hidden" name="id"  value="xx"/>
mvbrakel
  • 936
  • 5
  • 16
  • I've already explained that this is the problem. Look at my answer. Regarding the mysql_ functions, that's not an answer. – EM-Creations Feb 03 '13 at 14:32
  • Undeleted this answer, because it IS different. My answer also provides a way to solve the base problem in stead of removing the notice, removing the reason for the notics – mvbrakel Feb 03 '13 at 15:07