Warning: mysql_fetch_row () expects parameter 1 to be resource, boolean given


Could someone tell me why did you mark this error in my code?


Warning: mysql_fetch_row () expects parameter 1 to be resource, boolean given in C: \ xampp \ htdocs \ dashboard \ PROJECTFINALLP4 \ registerbd.php on line 61 *

I try to make a record and keep it in a database that I created, I leave the code:


$host = "";
$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();
echo "<center><h1>USUARIO REGISTRADO EXITOSAMENTE</h1></center>";
asked by Emanuel Mejia 20.07.2017 в 01:53

3 answers


First you must fix the query.

$consulta = "INSERT INTO usuarios SET id = '$id', nombre = '$nombre', password = '$password'";
$query = mysql_query ($consulta, $conectar);

Notice that I use SET after the name of the table.

Second is to eliminate the mysql_fetch_row since it is not used in this type of commands.

I hope you have been useful.

answered by 20.07.2017 / 03:44

The problem is that mysql_fetch_row() expects a variable of type resource . You are passing as variable the variable $query . This takes the return value of the query that 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; it returns a Boolean variable.


answered by 20.07.2017 в 02:08

mysql_fetch_row works only with queries type select , not with insert into.

I do not really know why you need that line

answered by 20.07.2017 в 02:11