Guest User

Untitled

a guest
Sep 12th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. <?php
  2. /*Datos de conexion a la base de datos*/
  3. $db_host = "localhost";
  4. $db_user = "root";
  5. $db_pass = "root";
  6. $db_name = "MCC_02_2018";
  7. $conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
  8. if(mysqli_connect_errno()){
  9. echo 'No se pudo conectar a la base de datos : '.mysqli_connect_error();
  10. }
  11. ?>
  12.  
  13. <form action="" method="post" name="form1" id="form1" role="form" accept-charset="utf-8" style="width:100%;">
  14. <table align="center" style="width:100%;">
  15. <tr valign="baseline">
  16. <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>
  17. </tr>
  18. <tr valign="baseline">
  19. <td align="center" valign="top" width="100%" nowrap="nowrap" >
  20. <textarea name="titulo" cols="40" rows="5" id="titulo" required="required" accept-charset="utf-8" placeholder="Introduce el título del post">
  21. </textarea>
  22. </td>
  23. </tr>
  24. <tr valign="baseline">
  25. <td align="center" valign="top" width="100%" nowrap="nowrap" >
  26. <textarea name="entradilla" cols="40" rows="5" id="entradilla" required="required" accept-charset="utf-8" placeholder="Entradilla del post">
  27. </textarea>
  28. </td>
  29. </tr>
  30. <tr valign="baseline">
  31. <td align="center" valign="top" nowrap="nowrap" width="100%">
  32. <textarea name="articulo" cols="40" rows="5" id="articulo" required="required" accept-charset="utf-8" placeholder="Artículo del post" >
  33. </textarea>
  34. </td>
  35. </tr>
  36. <tr valign="baseline">
  37. <td align="center" valign="top" nowrap="nowrap" width="100%">
  38. <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" />
  39. </td>
  40. </tr>
  41. <tr valign="baseline">
  42. <td align="center" valign="top" nowrap="nowrap" width="100%">
  43. <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>
  44. </tr>
  45. <tr valign="baseline">
  46. <td align="center" valign="top" nowrap="nowrap" width="100%">
  47. <input type="submit" value="Publicar post" name="add" style="width:80%; max-width:1000px;" />
  48. </td>
  49. </tr>
  50. </table>
  51. </form>
  52.  
  53. $cek = mysqli_query($conexion, "SELECT * FROM posts WHERE nombre='$nombre'");
  54. if(mysqli_num_rows($cek) == 0){
  55. $insert = mysqli_query($conexion, "INSERT INTO posts(nombre, titulo, entradilla, articulo, fecha, year)
  56. VALUES('$nombre','$titulo', '$entradilla', '$articulo', '$fecha', '$year')") or die(mysqli_error());
  57. if($insert){
  58. echo '<div class="alerta_exito"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Los datos del nuevo post han sido guardados con éxito.</div>';
  59. }else{
  60. echo '<div class="alerta_fracaso"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Error. No se pudo guardar los datos. Inténtalo de nuevo</div>';
  61. }
  62.  
  63. }else{
  64. cho '<div class="alerta_fracaso"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Error. ¡Ya existe ese registro, dale un nuevo nombre!</div>';
  65. }
  66. }
  67. ?>
Add Comment
Please, Sign In to add comment