<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php session_start(); // if don't have session user..then if(!isset($_SESSION["staname"])){ die("<script>alert('Please login first!'); window.location.href='login.html'; </script>"); session_write_close(); } ?> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Edit</title> <link rel="shortcut icon" href="images/logo.png" type="image/x-icon" /> <style> body{ background-color:#212121; } .card{ background-color:#303030; color:#fff; padding: 10px; width: 50%; border-radius: 5px; box-shadow: 0 3px 20px rgba(0, 0, 0, 0.4); margin-left:350px; margin-top:140px; } input{ box-shadow: 0 3px 20px rgba(0, 0, 0, 0.4); border-radius: 2px; background-color:#4f4f4f; color:white; width:220px; padding:5px; margin-top: 5px; } </style> </head> <body> <div class="card"> <center><h1 style="color:#edbb00;">Edit Item</h1> <!--Step 1: use PHP to read database--> <?php //a. get id from URL $uid = $_GET['id']; //b. connect to datdabase include "conn.php"; //c. write the sql query $sql = "Select * from item where Item_Name = '$uid'"; //d. execute the sql query $result=mysqli_query($conn,$sql); ?> <?php //get the data from the database into array and display in HTML Form if($rows=mysqli_fetch_array($result)) { //build the form and use echo to display the relevance data inside HTML form. ?> <!--Step 2: use HTML Form and PHP to display the result--> <form method="post" action="update.php" enctype="multipart/form-data"> <table style="text-align:left"> <tr><th width="200px">Item Name</th> <td><input type="text" value="<?php echo $uid;?>" name="uid" readonly/></td> </tr> <tr><th>Item Description</th> <td><input type="text" name="itemdesc" required="required" value="<?php echo $rows['Item_Desc']?>"/></td> </tr> <tr><th>Item Category</th> <td><input type="text" name="itemcat" required="required" value="<?php echo $rows['Item_Category']?>"/></td> </tr> <tr><th>Item Image</th> <td><?php echo '<img src="' .$rows['Item_Image'] . '" width="100" height="100" />' ?><input type="file" name="image" value=""/></td> </tr> <tr><th>Item Stock</th> <td><input type="text" name="itemstock" required="required" value="<?php echo $rows['Item_Stock']?>"/></td> </tr> <tr><th>Item Price</th> <td><input type="text" name="itemprice" required="required" value="<?php echo $rows['Item_Price']?>"/></td> </tr> <!-- add a update button for this page--> <tr><td colspan="2"> <br /> <center><input style="background-color: Green; border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer;" type="submit" value="Update"/> <input style="background-color: #d98900; border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer;" type="submit" value="Back to Previous Page" formaction="view.php"/> </center> </td> </tr> </table> </form> <?php } else { die("<script>alert('No such items'); window.location.href='view.php'</script>"); } ?> </center> </div> </body> </html>