I want to recognize the cpf in the table, display a page with other data. Where am I going wrong?

1
  

Warning: mysql_num_rows () expects parameter 1 to be resource, object given in C: \ xampp \ htdocs \ solidarity \ associates.php on line 15

My php code

<?php

include"conectar.php";

// RECEBENDO OS DADOS PREENCHIDOS DO FORMULÃ?RIO !
// $funct       = $_POST ["funct"]; //atribuição do campo "nome" vindo do formulário para variavel   
$cpf = $_POST ["cpf"];  //atribuição do campo "cpf" vindo do formulário para variavel

$query="select cpf from teste where cpf = '" . $cpf . "'";
        $stmt = mysqli_query( $con, $query);
if( $stmt === false) {
    die( print_r( mysqli_error($con), true) );
}
else
    {$rows = mysql_num_rows($stmt);
     if ($rows === true) {
     include('index.php');}
      else
      {include('dr-adesao.php');}
    }  

mysqli_close( $con );
?>

My connection is working!

I believe the error is in the PHP file!

    
asked by anonymous 31.10.2017 / 01:04

1 answer

0

The error is occurring because you are using the old method of the MySQL extension mysql_num_rows should change to the new method mysqli_num_rows .

The% method of% gets the number of rows of a result and not a Boolean value, it should change the line:

if ($rows === true)

To:

if ($rows === 1)

Or

if ($rows > 0)

Remove the space on the line

$cpf = $_POST ["cpf"];
             ^
$cpf = $_POST["cpf"]; // Deixe assim

To return the data you must change your SQL Query from:

$query="select cpf from teste where cpf = '" . $cpf . "'";

To:

$query="select conlunaA, colunaB, colunaC from teste where cpf = '{$cpf}'";

Change columnA, columnB, columnC to the name of the columns that contain your table.

    
31.10.2017 / 01:21