<?php

/*CONEXAO COM O BANCO*/
include "Connections/config.php";
/*********************/

$res = $db->query("SELECT * FROM advert WHERE id='" . $_GET["update"] . "'");
$row = $res->fetch_array();
$iId = $row["id"];
$iTitle = $row["title"];
$idescription = $row["description"];
$iurl = $row["url"];
if (isset($_POST["submit"])) {
    $db->query("UPDATE advert SET title='" . $_POST["title"] . "'," . "\r\n\t\t\t\t\t\t\t" . "  description='" . $_POST["description"] . "'," . "\r\n\t\t\t\t\t\t\t" . "  url='" . $_POST["url"] . "'" . "\r\n\t\t\t\t\t\t" . "  WHERE " . "\r\n\t\t\t\t\t\t\t" . "  id='" . $_POST["id"] . "'");
    header("Location: advert.php");
}
include "includes/header.php";
echo "        <div class=\"container-fluid\">\n\n          <!-- Page Heading -->\n          <h1 class=\"h3 mb-1 text-gray-800\"> Adverts</h1>\n\n              <!-- Custom codes -->\n                <div class=\"card border-left-primary shadow h-100 card shadow mb-4\">\n                <div class=\"card-header py-3\">\n                <h6 class=\"m-0 font-weight-bold text-primary\"><i class=\"fa fa-comment\"></i> Edit Advert</h6>\n                </div>\n                <div class=\"card-body\">\n                        <form method=\"post\">\n                        <div class=\"form control\">\n                                    <div class=\"form-group \">\n                                    <label class=\"control-label \" for=\"name\"><strong>Title</strong>\n                                    </label>\n                                    <div class=\"input-group\">\n";
echo "                                        <input class=\"form-control text-primary\" id=\"id\" name=\"id\"  value=\"" . $iId . "\" type=\"hidden\"/>" . "\n";
echo "                                        <input class=\"form-control text-primary\" id=\"title\" name=\"title\"  value=\"" . $iTitle . "\" type=\"text\"/>" . "\n";
echo "                                    </div>\n                                    </div>\n                                    <div class=\"form-group \">\n                                    <label class=\"control-label \" for=\"url\"><strong>Description</strong>\n                                    </label>\n                                    <div class=\"form-group\">\n";
echo "                                        <input class=\"form-control text-primary\" id=\"description\" name=\"description\" value=\"" . $idescription . "\" type=\"text\"/>" . "\n";
echo "                                    </div>\n                                    </div>\n                                    <div class=\"form-group \">\n                                    <label class=\"control-label \" for=\"url\"><strong>Image Url</strong>\n                                    </label>\n                                    <div class=\"form-group\">\n";
echo "                                        <input class=\"form-control text-primary\" id=\"url\" name=\"url\" value=\"" . $iurl . "\" type=\"text\"/>" . "\n";
echo "                                    </div>\n                                </div>\n                                <div class=\"form-group\">\n                                    <div>\n                                        <button class=\"btn btn-success btn-icon-split\" name=\"submit\" type=\"submit\">\n                        <span class=\"icon text-white-50\"><i class=\"fas fa-check\"></i></span><span class=\"text\">Submit</span>\n                        </button>\n                                    </div>\n\n                                </div>\n                            </form>\n                </div>\n              </div>\n            </div>\n";
include "includes/footer.php";
echo "</body>\n\n</html>";

?>