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/60100;
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);
}
?>