Show Code: medium-update.php

<?php include 'session.php'?> <!DOCTYPE html>
<html>

<head>
    <title>Alexandria</title>
    <link href="style1.css" rel="stylesheet" type="text/css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!--Refresh back to mediums read page-->
    <?php if(!empty($_POST['medium_name'])){  ?>
    <meta http-equiv="refresh" content="0.5;URL='mediums-read.php'">
    <?php }  ?>
</head>

<body>
    <?php include 'nav.php'?>
    <?php include 'db-connect.php'?>
    <main>
        <?php
        
        
if(empty($_POST)){  
            
//if the user has just clicked on edit
            
$medium_id=$_GET['medium_id'];
            
            
$sql='SELECT * FROM t_mediums WHERE medium_id='.$medium_id;
            
            
$result=mysqli_query($con,$sql);     
            
$row=mysqli_fetch_array($result);
        
    
?>
        <form method="post" action="medium-update.php">
            <input type="text" name="medium_name" value="<?php  echo $row['medium_name']?>">

            <!--Pass hidden medium_id as well-->
            <input type="hidden" name="medium_id" value="<?php  echo $medium_id?>">
            <input type="submit" value="Update">
        </form>
        <?php 
   
}
   else{    
    
//otherwise - recursive form handling   
    
$medium_name=$_POST['medium_name'];
    
$medium_id=$_POST['medium_id'];

    
$sql='UPDATE t_mediums SET medium_name="'.$medium_name.'"
    WHERE medium_id='
.$medium_id;
       
    if(
mysqli_query($con,$sql)){
        echo 
'medium has been updated';
    }
    else{
        echo 
"Error updating medium: " mysqli_error($con);
    }  
 }  
?>

        <?php mysqli_close($con);  //Close Connection?>
    </main>
</body>

</html>