Salim Shari
Salim Shari

Reputation: 13

Why does MySQL expect a parameter in this case

I just want to get an email from a customer table and send message to that email. I am getting this error

"Warning: mysql_num_rows() expects parameter 1 to be"

My code is as follows:

<?php
       $mysql = mysql_connect("localhost", "hname", "passs", "dbname");

       $getusers = mysql_query("SELECT * FROM customer");
       while ($row = mysql_fetch_array($result)) {
       sendMail($row['email']);
       }
       mysql_free_result($result);
       function sendMail($to){
       $subject = 'the subject';
       $message = 'hello';
       $headers = 'From: [email protected]' . "\r\n" .
       'Reply-To: [email protected]' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
       mail($to, $subject, $message, $headers);
       }
?>

Upvotes: 0

Views: 50

Answers (2)

Devang Rathod
Devang Rathod

Reputation: 6736

You can try this code :

while ($row = mysql_fetch_array($result)) {

TO

while ($row = mysql_fetch_array($getusers)) {

Upvotes: 0

Mike Brant
Mike Brant

Reputation: 71384

You are making a myslqi connection but then using mysql_* (no i) functions. You should use all mysqli.

Upvotes: 5

Related Questions