Could someone tell me why I get this error in my code?
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\dashboard\PROYECTOFINALLP4\registrobd.php on line 61*
I try to make a record and save it in a database that I have created, I leave the code:
<?php
$host = "127.0.0.1";
$user = "root";
$password = "";
$conectar = mysql_connect ($host, $user, $password);
mysql_select_db("proyectofinallp4", $conectar);
$id = $_POST["id"];
$nombre = $_POST["nombre"];
$password = $_POST["password"];
$consulta = "INSERT INTO usuarios id = '$id', nombre = '$nombre', password = '$password'";
$query = mysql_query ($consulta, $conectar);
$resultado = mysql_fetch_row ($query); //ESTA ES LA LINEA 61
if ($query == null) {
echo "<center><h1>ERROR AL REGISTRAR</h1></center>" . mysql_error();
}
else
{
echo "<center><h1>USUARIO REGISTRADO EXITOSAMENTE</h1></center>";
}
?>
The problem is that it
mysql_fetch_row()
expects a variable of typeresource
. You are passing the variable as a parameter$query
. This takes the return value of the query you are executing.According to the PHP documentation, if you execute a query of type: SELECT, SHOW, DESCRIBE, EXPLAIN, among others, with mysql_query the function returns a variable of type
resource
. But if it is of type INSERT, UPDATE, DELETE, DROP, etc; returns a boolean variable.Documentation:
First you have to fix the query.
Notice that I use SET after the table name.
Second is to remove the
mysql_fetch_row
since it is not used in this type of commands.I Hope I've been helpful.
mysql_fetch_row
only works with type queriesselect
, not with insert into.I don't really know why you need that line