Show Code: movement-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 movements read page-->
    <?php if(!empty($_POST['movement_name'])){  ?>
    <meta http-equiv="refresh" content="0.5;URL='movements-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
            
$movement_id=$_GET['movement_id'];
            
            
$sql='SELECT * FROM t_movements WHERE movement_id='.$movement_id;
            
            
$result=mysqli_query($con,$sql);     
            
$row=mysqli_fetch_array($result);
        
    
?>
        <form method="post" action="movement-update.php">
            <label>Movement Name</label>
            <input type="text" name="movement_name" value="<?php  echo $row['movement_name']?>">

            <label>Movement Description</label>
            <textarea name="movement_description"><?php  echo $row['movement_description']?></textarea>

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

    
$sql='UPDATE t_movements SET movement_name="'.$movement_name.'", movement_description="'.addslashes($movement_description).'"
    WHERE movement_id='
.$movement_id;
       
    if(
mysqli_query($con,$sql)){
        echo 
'movement has been updated';
    }
    else{
        echo 
"Error updating movement: " mysqli_error($con);
    }  
 }  
?>

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

</html>