-5

I'm using this script to update my MySQL database via a PHP form. But for some reason I get the notice: undifined index when I try to update... Could someone tell me why I'm getting the error.

Undifined Index: Melding on line 75

    <html>
<body>
<?php
$server="localhost";
$username="root";
$password="";
$connect_mysql=mysql_connect($server,$username,$password) or die ("Connection Failed!");
$mysql_db=mysql_select_db("helpdesk_middenpolder",$connect_mysql) or die ("Could not Connect to Database");
$query = "SELECT * FROM incidenten";
$result=mysql_query($query) or die("Query Failed : ".mysql_error());
$i=0;
while($rows=mysql_fetch_array($result))
{
$roll[$i]=$rows['incidentID'];
$i++;
}
$total_elmt=count($roll);
?>
<form method="POST" action="">
Select the Roll No. to Update: <select name="incidentID">
<option>Select</option>
<?php 
for($j=0;$j<$total_elmt;$j++)
{
?><option><?php 
echo $roll[$j];
?></option><?php
}
?>
</select><br />
<td>Hardwaretypen</td>
    <td>:</td>
    <td>
    <select name="typen" id="typen" <?php //Include de pagina waar je config file staat
    include 'dbconnectie.php';
    //Query
    $query = "SELECT typen FROM hardware_typen";
    //Query uitvoeren
    $uitvoeren = mysql_query($query);
    //Begin van dropdown
    echo '<select>';
    //While voor data in de dropdown
    while($rij = mysql_fetch_assoc($uitvoeren)) {
    //De data in de dropdown zetten
    echo '<option>'.$rij['typen'].'</option>';
    }
    //De dropdown beëindigen
    echo '</select>';?></td>
Melding: <input name="marks" type="text" /><br />
<select name="naam" id="naam" <?php //Include de pagina waar je config file staat
    include 'dbconnectie.php';
    //Query
    $query = "SELECT naam FROM gebruikers WHERE level='3'";
    //Query uitvoeren
    $uitvoeren = mysql_query($query);
    //Begin van dropdown
    echo '<select>';
    //While voor data in de dropdown
    while($rij = mysql_fetch_assoc($uitvoeren)) {
    //De data in de dropdown zetten
    echo '<option>'.$rij['naam'].'</option>';
    }
    //De dropdown beëindigen
    echo '</select>';?></td>
<input name="submit" type="submit" value="Update"/><br />
<input name="reset" type="reset" value="Reset"/>
</form>

<?php

if(isset($_POST['submit']))
{
$value=$_POST['incidentID'];
$typen=$_POST['typen'];
$melding=$_POST['Melding'];
$naam=$_POST['naam'];

$query2 = "UPDATE incidenten SET typen='$typen',Melding='$melding', WHERE incidentID='$value'";
$result2=mysql_query($query2) or die("Query Failed : ".mysql_error());
echo "Successfully Updated";
}
?>
<p align=right><a href="view.php">VIEW RECORDS</a></p>
<p align=right><a href="index.php">HOME</a></p>
halfer
  • 19,824
  • 17
  • 99
  • 186
niekerd1
  • 1
  • 4
  • You have no form element with `name="Melding"`. – deceze Jun 03 '14 at 09:00
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jun 03 '14 at 09:00
  • Please [learn to love labels](http://www.456bereastreet.com/archive/200711/use_the_label_element_to_make_your_html_forms_accessible/) – Quentin Jun 03 '14 at 09:01
  • 1
    To mark the question as solved, accept the answer you prefer, and/or upvote answers you liked. We prefer questions not to be marked as "works" or "solved" etc - the tick/check mark does that. – halfer Jun 03 '14 at 09:04

2 Answers2

0
Melding: <input name="marks" type="text" /><br />
                      ^^^^^^

You've named your input marks, not Melding.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Each index in the $_POST is a form field. you lack the melding field.

Kyle Emmanuel
  • 2,193
  • 1
  • 15
  • 22