Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Galeria</title>
- <meta charset="utf-8">
- <style type="text/css">
- button {
- background-color: rgb(236, 240, 241);
- border: none;
- color: black;
- text-align: center;
- text-decoration: none;
- display: inline;
- }
- a:link {
- color: black;
- text-decoration: none;
- }
- a:visited {
- color: black;
- text-decoration: none;
- }
- a:hover {
- color: black;
- text-decoration: none;
- }
- a:active {
- color: black;
- text-decoration: none;
- }
- .nav{
- background-color: rgb(63, 195, 128);
- border-radius: 7px;
- text-align: center;
- padding-bottom: 1px;
- padding-top: 3px;
- }
- body{
- background-color: rgb(46, 49, 49);
- color: white;
- font-family: "Comic Sans Ms"
- }
- fieldset{
- margin-left: auto;
- margin-right: auto;
- width: 550px;
- height: 300px;
- }
- .form{
- padding-top: 20px;
- text-align: center;
- font-size: 30px;
- }
- .form2{
- padding-top: 20px;
- text-align: center;
- font-size: 30px;
- }
- .erro{
- background-color: rgb(192, 57, 43);
- width: 300px;
- margin-left: auto;
- margin-right: auto;
- }
- .erro,.sucesso,.ok{
- text-align: center;
- }
- .sucesso,.ok{
- background-color: rgb(30, 130, 76);
- width: 300px;
- margin-left: auto;
- margin-right: auto;
- }
- </style>
- </head>
- <body>
- <?php
- $bd_host="localhost";
- $bd_user="root";
- $bd_password="";
- $bd_database="galeria";
- $mysqli = new mysqli($bd_host,$bd_user,$bd_password,$bd_database);
- // Mostrar erros, caso existam
- if ($mysqli->connect_error) {
- die('Erro: ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
- }
- $msg="";
- $leq1=$leq2=$llocal=$ldata=$lg1=$lg2='';
- ?>
- <div class="nav">
- <h1>Galeria</h1>
- <nav><button>Gerenciar Galeria</button><button><a href="galeria2.php" target="_self">Ver Galeria</a></button></nav>
- </div>
- <div class="form">
- <form method="POST" action="">
- <label>Tipo:</label> <input type="text" name="tipo"> <input type="submit" name="submitx" value="Novo"><br>
- <?php
- if (isset($_POST["submitx"])){
- if($_POST['tipo']==''){
- $msg='<h3 class="erro">Erro, Existem campos por preencher!</h3>';
- }
- else{
- $query = "INSERT INTO galeria(tipo) VALUES (?)";
- $statement = $mysqli->prepare($query);
- $statement->bind_param('s', $_POST["tipo"]);
- if ($statement->execute() && $statement->affected_rows>0){
- $msg= "<div class='ok'>Foi inserido/atualizado um registo!</div>";}
- $statement->close();
- }
- }
- ?>
- </form>
- </div>
- <div class="form2">
- <form method="post" enctype="multipart/form-data">
- <fieldset>
- <legend>Informações:</legend>
- Imagem: <input type="file" name="imagem" value=""><br>
- Titulo: <input style="width: 296px;"type="text" name="titulo"><br>
- Descrição: <input style="width: 238px;" type="text" name="descricao"><br>
- Tipo: <select name="123" style="width: 321px; height: 25px;"><br>
- <?php
- $qr="SELECT tipo FROM galeria";
- $st = $mysqli->query($qr);
- while($row = $st->fetch_assoc())
- {
- echo '<option value = "'.$row['tipo'].'">'.$row['tipo'].' </option>';
- }
- $st->close();
- ?>
- </select><br>
- Data: <input style="width: 312px;" type="date" name="data"><br>
- <input type="submit" name="submitz" value="Inserir"><br>
- </fieldset>
- </form>
- </div>
- <?php
- if(isset($_POST['submitz']))
- {
- if($_POST['titulo']=='' || $_POST['descricao']=='' || $_POST['data']==''){
- $msg='<h3 class="erro">Erro, Existem campos por preencher!</h3>';
- }
- else{
- $destino = "fotos/a" . $_POST['titulo'] . ".jpg" ;
- if($_FILES["imagem"]["type"]=="image/jpeg"){
- if(move_uploaded_file($_FILES['imagem']['tmp_name'], $destino)) {
- // echo '<img src="' . $destino. '">';
- $qr = "INSERT INTO galeria_fotos (imagem,titulo,descricao,data,tipo) VALUES(?,?,?,?,?)";
- $st = $mysqli->prepare($qr);
- $st->bind_param('sssss',$destino, $_POST["titulo"], $_POST["descricao"], $_POST["data"],$_POST["123"]);
- if ($st->execute() && $st->affected_rows>0){
- $msg='<h3 class="sucesso">A fotografia foi inserida!</h3>';
- }
- else{
- $msg='<h3 class="erro" >Erro: ('. $mysqli->errno .') '. $mysqli->error . '</h3>';
- $erro=1;
- }
- $st->close();
- }
- }
- }
- }
- ?>
- <?php
- echo "<br>";
- echo $msg;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement