PHP unresponsive in fetch command

2

I'm studying with a book use the head and the following practically copied and pasted the sample code just changing the names of the variables and I'm not having the return with my code, actually what appears in my final result is email Sent to: 3x this because I have 3 entries in my database, but the values are not being placed inside the variables logo, the function is not working right, is not sending email nor return email sent to: [email protected] Since I thank you already.

<?php
  $de = '[email protected]';
  $assunto = $_POST['assunto'];
  $texto = $_POST['elvismail'];

  /*creating connection*/
  $conexao = mysqli_connect('localhost', 'root', 'password', 'ELVIS_STORE')
  or die ('Erro ao conectar o banco');  

  /*command SQL*/
  $query = "SELECT * FROM LISTA_EMAIL"; 

  /*getting result*/
  $result = mysqli_query($conexao, $query) or die ('erro na segunda etapa');   

  while ($row = mysqli_fetch_array($result))
 {
   $para = $row['email'];
   $nome = $row['nome'];
   $sobrenome = $row['nome'];
   mail($para, $assunto, $texto, 'De: ' . $de);
   echo 'Email sent to: ' . $para . '<br />';
 }
  mysqli_close($conexao);
?>
    
asked by anonymous 08.07.2016 / 12:05

1 answer

0

First: table name is in MAIL ? Second: Are the connections correct? Third: The constant changes from PHP to MySQL (depreciation of mysql_ * against mysqli_ *) made me research and guide you to change, after SELECT, the code snippet like this:

if ($stmt = mysqli_prepare($link, $query)) {

/* execute statement */
mysqli_stmt_execute($stmt);

/* bind result variables */
mysqli_stmt_bind_result($stmt, $name, $code);

/* fetch values */
while (mysqli_stmt_fetch($stmt)) {
    printf ("%s (%s)\n", $name, $code);
}

/* close statement */
mysqli_stmt_close($stmt);
}

I hope I have helped.

    
08.07.2016 / 14:28