Error in CRUD form: Warning: mysqli_error () expects exactly 1 parameter, 0 given in

0

I have a problem with the error that is indicated in the statement of my question. The connection file, called conexion_2.php , has the following content:

<?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();
}
?>

On the other hand, the connection is made and it does not give me any error.

The form in question is the following:

<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>

The script that uploads the form data to the bbdd, and where the problem appears, is the following:     

    $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">&times;</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">&times;</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">&times;</button>Error. ¡Ya existe ese registro, dale un nuevo nombre!</div>';
            }
        }
    ?>

and here comes the problem, and it gives the following Warning (and of course it does not write in the bbdd):

  

Warning: mysqli_error () expects exactly 1 parameter, 0 given in   /Applications/MAMP/htdocs/MCC/MCC_01/__admin/edicion.php on line 135

Line 135 of my code is as follows:

VALUES('$nombre','$titulo', '$entradilla', '$articulo', '$fecha', '$year')") or die(mysqli_error());

Can you help me? Thank you very much and I feel the great extension of my question.

Greetings

    
asked by Ml Saura 12.09.2018 в 14:49
source

1 answer

1

You have to pass the connection to mysqli_error:

die(mysqli_error($conexion));

This will tell you the error you have when executing the sql

    
answered by 12.09.2018 / 14:54
source