无法找到我的错误。从$ _POST获取数据时

时间:2019-03-21 21:16:22

标签: php

问候'im试图从$_POST方法形式获取数据。不幸的是,我从服务器(localhost)收到此警告

  

警告:mysqli_error()恰好期望1个参数,第9行的C:\ xampp \ htdocs \ justificativo \ listadoasignado.php中给出的参数为0

代码是下一个

<?php
include("conecta.php");
$c1 = $_POST['rut'];
$c2 = $_POST['nivel'];
$c3 = $_POST['unidad'];
$c4 = $_POST['entidad'];
$c5 = $_POST['reposo'];
$query = mysqli_query($con, "INSERT INTO certificado (id_detalle, n_alumno, n_nivel, n_unidad, dia_reposo) VALUES ('$c1', '$c2', '$c3', '$c4', '$c5')")
or die(mysqli_error());
?>

2 个答案:

答案 0 :(得分:2)

您需要通过$con,因为$con拥有数据库连接

die(mysqli_error($con));

答案 1 :(得分:0)

您使用mysqli_error函数错误。它需要一个参数(连接)。 https://www.w3resource.com/php/function-reference/mysqli_error.php

正确使用:

<?php
include("conecta.php");
$c1 = $_POST['rut'];
$c2 = $_POST['nivel'];
$c3 = $_POST['unidad'];
$c4 = $_POST['entidad'];
$c5 = $_POST['reposo'];
$query = mysqli_query($con, "INSERT INTO certificado (id_detalle, n_alumno, n_nivel, n_unidad, dia_reposo) VALUES ('$c1', '$c2', '$c3', '$c4', '$c5')")
or die(mysqli_error($con));
?>