-2

Im making a newsletter on my website in my school project.

It works fine, and emails will appear on my database when I type in. But I get an error:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given in /customers/4/8/8/web-line.dk/httpd.www/TACO/forside.php on line 19

I can't figure out what it wants me to do.

My code:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


$email="";


if (isset($_POST['signup-button'])){


include_once "Connect_db.php";

#$name=$_POST['name'];
$email=$_POST['signup-email'];

$sql=mysqli_query($mysqli,"SELECT*FROM newsletter WHERE 
email='$email'");
$numRows=mysqli_num_rows($sql);

if(!$email){
echo "Udfyld email";
}


else if ($numRows > 0){
echo "Email allerede i system!";
}

else {
$sql_insert=mysqli_query($mysqli,"INSERT INTO newsletter (email, 
dateTime)
VALUES ('$email', now())") or die (mysqli_error($mysqli));
}



}


?>  
Shadow
  • 33,525
  • 10
  • 51
  • 64

3 Answers3

-1

You need to add spaces in the SELECT query:

$sql=mysqli_query($mysqli,"SELECT * FROM `newsletter` WHERE `email`='$email'");

That maybe the issue that it is not able to recognize the query and throwing the error and I am assuming that $mysqli is a connection object defined in the connection file "Connect_db.php".

Hope this helps.

Kishen Nagaraju
  • 2,062
  • 9
  • 17
-1

If the select query assigned to $sql fails then the $numRows=mysqli_num_rows($sql); statement will fail. Try handling any potential errors in the select before calling mysqli_num_rows()

Mark
  • 1
-1

Change $numRows=mysqli_num_rows($sql); to $numRows= $sql->mysqli_num_rows();

Slawomir Wozniak
  • 489
  • 6
  • 14