Jump to content


Photo

Chapter 3 Php Error In Sendemail.php


  • Please log in to reply
2 replies to this topic

#1 Rusudan Tsiskreli

Rusudan Tsiskreli

    New Member

  • Members
  • Pip
  • 1 posts
  • Gender:Female

Posted 23 November 2014 - 01:24 AM

Hello
The code given in book:
<?php
$from = 'tsiskreli@highlander.ge';
$subject = $_POST['subject'];
$message = $_POST['elvismail'];

$dbc = mysqli_connect('localhost', 'toursukr_learn', 'KarambA77', 'toursukr_learning' )
or die('Error connecting to MySQL database server.');

$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc, $query);

while ($row = mysqli_fetch_array($result)){
$first_name = $row['first_name'];
$last_name = $row['last_name'];

$msg = "Dear $first_name $last_name, \n $message";
$mail = $row['email'];
mail($mail, $subject, $msg);
echo 'Email sent to:' . $mail . '<br />';
}
?>

Causes next error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/toursukr/public_html/php/sendmail.php on line 12

Line 12 is exactly while loop.

#2 Alexey Willchancesky

Alexey Willchancesky

    New Member

  • Members
  • Pip
  • 1 posts

Posted 28 November 2014 - 03:52 AM

Hello
The code given in book:
<?php
$from = 'tsiskreli@highlander.ge';
$subject = $_POST['subject'];
$message = $_POST['elvismail'];

$dbc = mysqli_connect('localhost', 'toursukr_learn', 'KarambA77', 'toursukr_learning' )
or die('Error connecting to MySQL database server.');

$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc, $query);

while ($row = mysqli_fetch_array($result)){
$first_name = $row['first_name'];
$last_name = $row['last_name'];

$msg = "Dear $first_name $last_name, \n $message";
$mail = $row['email'];
mail($mail, $subject, $msg);
echo 'Email sent to:' . $mail . '<br />';
}
?>

Causes next error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/toursukr/public_html/php/sendmail.php on line 12

Line 12 is exactly while loop.


I think it is because your $result == false (boolean) because you have problems with connection to database.

#3 Dida

Dida

    New Member

  • Members
  • Pip
  • 2 posts

Posted 05 March 2015 - 06:14 AM

I think you forgot to add : mysqli_close($dbc); before the ?>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users