Friday, 6 September 2019

edit


<?php
$con=mysqli_connect("localhost","root","","myschool");
$sql="SELECT * FROM school";
$result=mysqli_query($con,$sql);
if($result)
{
          echo "Now You can access data";
}
   if(mysqli_num_rows($result)>0 )
{
?>
<html>
<head>
<link rel="stylesheet" href="table.css">
</head>
<body>
<form  method="POST" action="<?php $_PHP_SELF ?>">
<table border="2" align="center">

<tr><caption>Students details</caption></tr>
<tr><th>RollNo.</th>
<th>Student_Name</th>
<th>Father_Name</th>
<th>Class.</th>
<th>Gender</th>
<th>Course</th>
<th>Update</th>
<th>Delete</th></tr>
<?php
while($row= mysqli_fetch_assoc($result))
          {
?>
<tr><td ><?php echo $row['ID']; ?></td>
<td><?php echo $row['s_name'];?> </td>
<td><?php echo $row['F_name'];?> </td>
<td><?php echo $row['Class']; ?></td>
<td><?php echo $row['Gender'];?> </td>
<td><?php echo $row['Cource'];?> </td>
<?php echo "<td><a href=' edi3.php?ID=".$row['ID']."'>Update</a></td>";?>
<?php echo "<td><a href=' del.php?id=".$row['ID']."'>del</a></td>";?>
 <?php }}?>
</tr>
</table>
</form>
</body>
</html>

Edi3.php
<?php
#require('con1.php');
$conn= new mysqli("localhost","root","","myschool");

if (!$conn) {

    die("Connection failed: " . mysqli_connect_error());
}
else
{

$ID=$_REQUEST['ID'];
$query = "SELECT * from school where ID='".$ID."'";
$result = mysqli_query($conn, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
}
?>

<html>
<head>

<title>Update Record</title>

</head>
<body>

<h1>Update Record</h1>
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$ID=$_REQUEST['ID'];

$name =$_REQUEST['name'];

$update="update school set s_name='".$name."' where ID='".$ID."'";
mysqli_query($conn, $update) or die(mysqli_error());
$status = "Record Updated Successfully. </br></br>
<a href='STUDENT.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
?>
<div>
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1" />
<input name="ID" type="hidden" value="<?php echo $row['ID'];?>" />
<p><input type="text" name="name" placeholder="Enter Name"
required value="<?php echo $row['s_name'];?>" /></p>

<p><input name="submit" type="submit" value="Update" /></p>
</form>
<?php } ?>
</div>
</div>
</body>
</html>