$row['id'] - undefined index

helmuntdavid

New Member
I am new to PHP. I am practicing how to delete a row in mysql using PHP. I have this code:\[code\]<?php$con = mysql_connect("localhost","root","");mysql_select_db("usersdb", $con);echo "<table border='1'><tr><th>USERNAME</th><th>PASSWORD</th><th>ACTION</th></tr>";$result = mysql_query("SELECT * FROM users");while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td>" . $row['username'] . "</td>";echo "<td>" . $row['password'] . "</td>";echo "<td>";echo '<a href="http://stackoverflow.com/questions/12766517/index.php?delete='.$row['id'].'">Delete</a></html>';echo "</td>";echo "</tr>";}echo "</table>";if(isset($_GET['delete']) and is_numeric($_GET['delete'])){ mysql_query("DELETE FROM Persons WHERE `id` = '".$_GET['delete']."'");}?>\[/code\]When I tested it on the browser, it gives this error: \[code\]Notice: Undefined index: id in C:\wamp\www\index.php on line 22\[/code\]The error is pointing at the $row['id']. I tried to defined it as $id = $row['id'] and replace $id on the line where $row['id'] is located. But in the end, I still get the same error. How can I solve this kind of error?
 
Top