I want to recognize Cpf in the table, display a page with other data. Where am I missing?

Asked

Viewed 30 times

1

Warning: mysql_num_rows() expects Parameter 1 to be Resource, Object Given in C: xampp htdocs associated.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 file PHP!

  • Read Why should we not use mysql type functions_*?. Alter $rows = mysql_num_rows($stmt); for $rows = mysqli_num_rows($stmt);

  • I made the change but even with Cpf already registered in the table, still sends me the page of table not affected!

  • Let’s take steps, the error has been fixed ? Remove the space on the line $cpf = $_POST ["cpf"] leaving so $cpf = $_POST["cpf"]

  • yes I fixed it, but it sent me to .. I want to follow up on.php and since Cpf is already in the table, I should send it to index.php

1 answer

0


The error is happening because you are using the old extension method Mysql mysql_num_rows shall change to the new method mysqli_num_rows.


The method mysqli_num_rows gets the number of lines of a result and not a value Boolean, 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 Query SQL of:

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

To:

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

Alter column A, column B, column C for the name of the columns containing your table.

  • Thank you wéllingthon! but I only have one column and this one is called Cpf.

  • I get it, it’s because I went by the title of the question.

  • let me ask you, is the error in mysqli_num_rows?

  • well I will try to be more specific... I have a Cpf number in the table, when typing on the screen the table number this screen sends me to a screen demonstrating the rest of the registration!

  • See that you started using mysqli_* at the time you are returning the number of lines that the query returned you are using mysql_num_rows I believe that this cause the problem, I have no way to test now.

  • I’ve changed it’s like this now

  • <?php include"connect.php"; // RECEIVING THE COMPLETED FORM DATA? RIO ! // $funct = $_POST ["funct"]; //§assignment is from the "name" field coming from the form for variable $Cpf=$_POST["Cpf"]; //§assignment is the "email" field coming from the form for variable $query="select Cpf from test Where Cpf = '{$Cpf}'"; $stmt = mysqli_query($con,$query); if($stmt === false) { die(print_r(mysqli_error($con), true) ); } Else {$Rows = mysqli_num_rows($stmt); if ($Rows === true) { include('index.php');} Else {include('dr-membership.php');} } ?>

  • Change the line if ($rows === true) for if ($rows > 0)

  • Thank you very much! You really helped me!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.