Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*Datos de conexion a la base de datos*/
- $db_host = "localhost";
- $db_user = "root";
- $db_pass = "root";
- $db_name = "MCC_02_2018";
- $conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
- if(mysqli_connect_errno()){
- echo 'No se pudo conectar a la base de datos : '.mysqli_connect_error();
- }
- ?>
- <form action="" method="post" name="form1" id="form1" role="form" accept-charset="utf-8" style="width:100%;">
- <table align="center" style="width:100%;">
- <tr valign="baseline">
- <td align="center" valign="top" width="100%" ><input name="nombre" type="text" id="nombre" placeholder="Nombre: Instrucciones bajo el epígrafe MUY IMPORTANTE" size="40" required="required" accept-charset="utf-8" style="width:80%; max-width:1200px; min-width: auto; display: flex; flex-direction: row; align-content: stretch;" class="text" /></td>
- </tr>
- <tr valign="baseline">
- <td align="center" valign="top" width="100%" nowrap="nowrap" >
- <textarea name="titulo" cols="40" rows="5" id="titulo" required="required" accept-charset="utf-8" placeholder="Introduce el título del post">
- </textarea>
- </td>
- </tr>
- <tr valign="baseline">
- <td align="center" valign="top" width="100%" nowrap="nowrap" >
- <textarea name="entradilla" cols="40" rows="5" id="entradilla" required="required" accept-charset="utf-8" placeholder="Entradilla del post">
- </textarea>
- </td>
- </tr>
- <tr valign="baseline">
- <td align="center" valign="top" nowrap="nowrap" width="100%">
- <textarea name="articulo" cols="40" rows="5" id="articulo" required="required" accept-charset="utf-8" placeholder="Artículo del post" >
- </textarea>
- </td>
- </tr>
- <tr valign="baseline">
- <td align="center" valign="top" nowrap="nowrap" width="100%">
- <input name="fecha" type="text" id="fecha" required="required" accept-charset="utf-8" placeholder="Fecha en formato: aaaa-mm-dd (ej: 2018-03-14)" size="40" />
- </td>
- </tr>
- <tr valign="baseline">
- <td align="center" valign="top" nowrap="nowrap" width="100%">
- <input name="year" type="text" id="year" required="required" placeholder="Escribir con números el año. Ej: 2018" accept-charset="utf-8" size="40" /></td>
- </tr>
- <tr valign="baseline">
- <td align="center" valign="top" nowrap="nowrap" width="100%">
- <input type="submit" value="Publicar post" name="add" style="width:80%; max-width:1000px;" />
- </td>
- </tr>
- </table>
- </form>
- $cek = mysqli_query($conexion, "SELECT * FROM posts WHERE nombre='$nombre'");
- if(mysqli_num_rows($cek) == 0){
- $insert = mysqli_query($conexion, "INSERT INTO posts(nombre, titulo, entradilla, articulo, fecha, year)
- VALUES('$nombre','$titulo', '$entradilla', '$articulo', '$fecha', '$year')") or die(mysqli_error());
- if($insert){
- echo '<div class="alerta_exito"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Los datos del nuevo post han sido guardados con éxito.</div>';
- }else{
- echo '<div class="alerta_fracaso"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Error. No se pudo guardar los datos. Inténtalo de nuevo</div>';
- }
- }else{
- cho '<div class="alerta_fracaso"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Error. ¡Ya existe ese registro, dale un nuevo nombre!</div>';
- }
- }
- ?>
Add Comment
Please, Sign In to add comment