示例#1
0
// validate the input and update the item information
// in the database.
if (isset($_POST["updatesubmit"])) {
    $itemName = escapeValue(trim($_POST["name"]));
    $itemPrice = trim($_POST["price"]);
    $itemDescription = escapeValue(trim($_POST["description"]));
    if (empty($itemName) || empty($itemPrice) || empty($itemDescription)) {
        echo "<h3>Error: Please fill in all inputs</h3>";
    } else {
        // check if any image is uploaded
        if (isset($_FILES["image"]["tmp_name"]) && !empty($_FILES["image"]["tmp_name"])) {
            // get the image content and encode it before
            // adding into the database
            $itemImage = addslashes($_FILES["image"]["tmp_name"]);
            $itemImage = base64_encode(file_get_contents($itemImage));
        }
        DataSource::updateItem($itemID, $itemName, $itemPrice, $itemDescription, $itemImage);
        redirectTo("myitems.php");
    }
}
closeConnection();
?>
                    </div> 
                </div>
                </form>
            </div>
        </div>
    </div>    
</main>
</body>
</html>