I know there are lot of question with same title but did not get any solution. My code is working perfect and data is editing correctly. But when i edit data and click on save button than data is saving but showing following error in input type :-
Notice: Undefined variable: row in E:\XAMPP\htdocs\practice\practice.php on line 33

Please check the code and send any solution please. Any kind of help will be appreciated. Thanks in advance

HTML :-

<div>
<form>
<input type="hidden" name="editid" value="<?php echo $row['id'];?>">
<div>Name <input type="text" name="name" value="<?php echo $row['name'];?>"/></div>
<div>Math <input type="text" name="math" value="<?php echo $row['math'];?>"/></div>
<div>History <input type="text" name="history" value="<?php echo $row['history'];?>"/></div>
<div>Computer <input type="text" name="computer" value="<?php echo $row['computer'];?>"/></div>
<div> <input type="submit" name="save" value="save"/></div>
</form>
</div>
<table border="2">
<tr>
<th>Id</th>
<th>Name</th>
<th>Math</th>
<th>History</th>
<th>Computer</th>
<th>Total</th>
<th>Percentage</th>
<th>Delete</th>
<th>Edit</th>
<th>Status</th>
</tr>
<?php
$query="select from practice";
$result=mysqli_query($connect,$query);
while($row=mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row['id'];?> </td>
<td><?php echo $row['name'];?> </td>
<td><?php echo $row['math'];?></td>
<td><?php echo $row['history'];?></td>
<td><?php echo $row['computer'];?></td>
<td>
<?php
$math=$row['math'];
$history=$row['history'];
$computer=$row['computer'];
$total=$math+$history+$computer;
echo "$total";
?>
</td>
<td>
<?php
$per=$total/60
100;
echo "$per";
?>
</td>

	<td><a href="practice.php?did=<?php echo $row['id']?>">Delete</a></td>
	<td><a href="practice.php?eid=<?php echo $row['id']?>">Edit</a></td>
	<td>  Active</td>
</tr>
<?php
	}
?>

</table>

And code:-

<?php
$connect=mysqli_connect("localhost","root","","practice") or die ("connection failed");
if(!empty($GET['save'])){
$name=$
GET['name'];
$math=$GET['math'];
$history=$
GET['history'];
$computer=$GET['computer'];
if(!empty($
GET['editid'])){
$id=$GET['editid'];
$query="update practice set name='$name',math='$math',history='$history',computer='$computer' where id=$id";
}
else{
$query="insert into practice (name,math,history,computer) values ('$name','$math','$history','$computer')";
}
header('location:practice.php');
mysqli_query($connect,$query);
}
if(!empty($
GET['did'])){
$id=$GET['did'];
$query="delete from practice where id=$id";
mysqli_query($connect,$query);
}
if(!empty($
GET['eid'])){
$id=$_GET['eid'];
$query="select * from practice where id=$id";
$result=mysqli_query($connect,$query);
$row=mysqli_fetch_assoc($result);
}
?>

    It might help if you could let us know which is line 33 of E:\XAMPP\htdocs\practice\practice.php.

    My educated guess is it's in this section:

    <input type="hidden" name="editid" value="<?php echo $row['id'];?>">
    <div>Name <input type="text" name="name" value="<?php echo $row['name'];?>"/></div>
    <div>Math <input type="text" name="math" value="<?php echo $row['math'];?>"/></div>
    <div>History <input type="text" name="history" value="<?php echo $row['history'];?>"/></div>
    <div>Computer <input type="text" name="computer" value="<?php echo $row['computer'];?>"/></div>

    You may need to do something like this for each of them:

    <input type="hidden" name="editid" value="<?php if(isset($row['id']) { echo $row['id']; } ?>">

    NogDog

    on 33:- <div>Name <input type="text" name="name" value="<?php echo $row['name'];?>"/></div>
    on 34:- <div>Math <input type="text" name="math" value="<?php echo $row['math'];?>"/></div>
    on 35:- <div>History <input type="text" name="history" value="<?php echo $row['history'];?>"/></div>
    on 36:- <div>Computer <input type="text" name="computer" value="<?php echo $row['computer'];?>"/></div>

      Or, put this at the top to rid yourself of those pesky notice errors: 😃

      error_reporting(E_ALL & ~E_NOTICE);

      Of course, the real solution is much as NogDog gave you, or, best, to not use $row when it's not been defined, but that adds to the complexity of the written code:

      $rowname = 
      $rowmath =
      $rowhist =
      $rowcomp = '';
      
      if (isset($row) && is_array($row) && !empty($row)) {
          $rowname = $row['name'];
          $rowmath = $row['math'];
          $rowhist = $row['history'];
          $rowcomp = $row['computer'];
      }
      
      //HTML stuff here using the four vars from above.
        Write a Reply...