简体   繁体   English

无法将数据插入mySQL数据库:INSERT查询看起来正常,并且错误日志将不显示任何内容

[英]Cannot insert data into mySQL database: the INSERT query looks ok and the error logs won't show a thing

I've got a mySQL error 我有一个mySQL错误

"Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, boolean given in /home/public_html/registroUsuario.php on line 22 Error Occurred 0 " “警告:mysqli_affected_rows()期望参数1为mysqli,在第22行的/home/public_html/registroUsuario.php中给出的布尔值出现0”

The file with the error takes information from an html form and inserts into a database. 出现错误的文件从html表单获取信息,然后插入数据库。 The file inserts the database credentials, so, the connection uses constants instead of the real values. 该文件将插入数据库凭据,因此,连接使用常量而不是实际值。

HTML FORM HTML格式

<form name="inscripcionForm" method="POST" action ="registroUsuario.php">
<input type="email" class="form-control" name="email" id="email">
<input type="apellido" class="form-control" name="apellido" id="apellido">
<input type="nombres" class="form-control" name="nombres" id="nombres">
<input type="dni" class="form-control" name="dni" id="dni">
<input type="pass" class="form-control" name="pass" id="pass">
<button type="submit" class="btn btn-primary pull-right">Inscribirme al Curso</button>
</form>

PHP PROCESSING OF THAT FORM (registroUsuario.php) 该表格的PHP处理(registroUsuario.php)

$email = strip_tags($_POST['email']);
$apellido = strip_tags(strtoupper($_POST['apellido']));
$nombres = strip_tags(ucfirst($_POST['nombres']));
$dni = strip_tags($_POST['dni']);
$pass = strip_tags($_POST['pass']);

$conectar = mysqli_connect(HOST, USER, PASS, DATABASE)
OR die('Oops! Error '.mysqli_connect_errno());

$query = "INSERT INTO usuarios (userID, userEmail, userApellido, userNombres, userDNI, userPass) VALUES ('', '$email', '$apellido', '$nombres', '$dni', '$pass')";
    $insertarBase = mysqli_query($conectar,$query);

    $affected_rows = mysqli_affected_rows($insertarBase);
        if($affected_rows == 1){
            echo 'New User!';
            mysqli_close($conectar);
        } else {
            echo 'Error Occurred '.mysqli_connect_errno();
            mysqli_close($conectar);
        }

My Error Log doesn't show anything, even if I do have error_reporting(E_ALL ^ E_NOTICE); 即使我有error_reporting(E_ALL ^ E_NOTICE);我的错误日志也什么也不显示error_reporting(E_ALL ^ E_NOTICE); at the top of the file. 在文件的顶部。

What should I do? 我该怎么办? Is the query wrongly constructed? 查询构造错误吗? Thanks! 谢谢!

As the error message states, mysqli_affected_rows expects a mysqli object as the parameter, while you're passing in a boolean. 如错误消息所述,在传递布尔值时, mysqli_affected_rows期望将mysqli对象作为参数。

Instead of 代替

$affected_rows = mysqli_affected_rows($insertarBase);

it should be 它应该是

$affected_rows = mysqli_affected_rows($conectar);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM