I am querying table in a while loop and has a button to update data for each row when clicked. But the update isn't happening .
The table column "Enroll" is to be updated based on clicking the submit button for that row.
<?php
$connection = mysql_connect('localhost', 'root', ''); 
mysql_select_db('mydata');
$query = "SELECT * FROM internship";
$result = mysql_query($query); 
while($row = mysql_fetch_array($result)){  
    if($row['Enroll']=="unenroll")
    { 
        echo '<div class="intern">';
        echo '<h1>'.$row['course'] . "</h1>" ;
        echo '<h2>'.$row['compay'] . "</h2>";
        echo "<h3>Stipend:Rs." . $row['stipend'] ."<h3>";
        echo "<h3>Duration:".$row['duration']."month</h3>";
        echo "<h3>Start-date:".$row['start date']."</h3>";
        echo '</div>';
        echo '<form method="post" action="">';
        echo '<button name="add_to_cart" type="submit" ><h2>Enroll</h2></button>';
        echo '</form>';
        if(isset($_POST["add_to_cart"]))
        {
            $selectedProduct =  $row["ID"];
            $sql='UPDATE internship SET Enroll="enrolled" WHERE ID="$selectedProduct"';
            mysql_query($connection,$sql);    
            header("location:enrolled.php");            
         }
     }
}
mysql_close($connection);
?>
I am not able to update. Please help.
 
     
    