0

I have a mistake in my database .. It is written that there is undefined index from line 41 until 50 in the code .. In my website I tried to insert data from a form to the PhpMyAdmin database and everything is working fine except this...

The error is : Notice: Undefined index: Services in C:\xampp\htdocs\ers\Database.php on line 41 - 50

Database.php :

<html>
<body>
<?php
$con = mysql_connect("localhost","root","123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code

?>


<table border="1">
    <tr >
        <td>Finding</td>
        <td>ServiceType</td>
        <td>Title</td>
        <td>RootCause</td>
        <td>RiskRating</td>
        <td>Impact</td>
        <td>Efforts</td>
        <td>Likelihood</td>
        <td>Finding</td>
        <td>Implication</td>
                <td>Recommendation</td>
                        <td>Report</td>
    </tr>


<?php





mysql_select_db ( "ers_1", $con);
$sql="INSERT INTO findings (ServiceType_ID, Title, RootCause_ID, RiskRating_ID, Impact_ID, Efforts_ID, Likelihood_ID, Finding,Implication,  Recommendation, Report_ID) VALUES (

    '$_POST[Services]',
    '$_POST[title]',
    '$_POST[RootCause]',
    '$_POST[RiskRating]',
    '$_POST[impact]',
    '$_POST[Efforts]',
    '$_POST[likelihood]',
    '$_POST[Finding]',
    '$_POST[Implication]',
    '$_POST[Recommendation]',
    '1'
    )";



$result = mysql_query("SELECT * FROM findings");

while($row = mysql_fetch_assoc($result)) 
  {
  echo "<tr>";
  echo "<td>" . $row['Finding_ID'] . "</td>";                                           
  echo "<td>" . $row['ServiceType_ID'] . "</td>";
  echo "<td>" . $row['Title'] . "</td>";
  echo "<td>" . $row['RootCause_ID'] . "</td>";
  echo "<td>" . $row['RiskRating_ID'] . "</td>";
  echo "<td>" . $row['Impact_ID'] . "</td>";
   echo "<td>" . $row['Efforts_ID'] . "</td>";
    echo "<td>" . $row['Likelihood_ID'] . "</td>";
    echo "<td>" . $row['Finding'] . "</td>";
    echo "<td>" . $row['Implication'] . "</td>";

    echo "<td>" . $row['Recommendation'] . "</td>";
    echo "<td>" . $row['Report_ID'] . "</td>";
  //echo "<td><a href='edit.php'>[EDIT]</a> <a href='delete_risk.php?risk_no=" . $row['risk_no'] . "'>[DELETE]</a></td>";
  echo "</tr>";
  }



mysql_close($con);
?> 

<input type="button" value="Back" onclick="window.location.href='option_Frame.php'" />

</body>
</html

>

  • Could you indicate which are the rows that give you the error? – andrewsi Aug 13 '12 at 20:24
  • 1
    It may not help answer your question, but you should stop using `mysql_*` functions. They're being deprecated. Instead use [PDO](http://php.net/manual/en/book.pdo.php) (supported as of PHP 5.1) or [mysqli](http://php.net/manual/en/book.mysqli.php) (supported as of PHP 4.1). If you're not sure which one to use, [read this article](http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/). – Matt Aug 13 '12 at 20:26
  • these are the rows : '$_POST[Services]', '$_POST[title]', '$_POST[RootCause]', '$_POST[RiskRating]', '$_POST[impact]', '$_POST[Efforts]', '$_POST[likelihood]', '$_POST[Finding]', '$_POST[Implication]', '$_POST[Recommendation]', – user1593177 Aug 13 '12 at 20:28
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – mario Aug 13 '12 at 20:33

2 Answers2

2

It sounds like $_POST['Services'] was not posted rather than this being a database issue.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
0

Check your HTML; there is probably no input element with name="Services".

Rogier Pennink
  • 388
  • 1
  • 12