Error: Undefined variable 'x' in 'local' [closed]

-7

I'm learning PHP , on the page this appears:

  

"Notice: Undefined variable: Tasks in C: \ xampp \ htdocs \ index.php on line 42."

Código PHP:
<?php

$bdServidor = '127.0.0.1';
$bdUsuario = 'felipe';
$bdSenha = 'testeteste123' ;
$bdbanco = 'tarefas' ;

$conexao = mysqli_connect($bdServidor,$bdUsuario,$bdSenha,$bdbanco);

if (mysqli_connect_errno($conexao)) 
{
echo "Problemas para conectar no banco. Verifique os dados!";
}
else
{
  echo "tudo ocorreu bem";
}
function busca_tarefas($conexao)
{
    $sqlBusca = 'SELECT * FROM tarefas';
    $resultado = mysql_query($conexao,$sqlBusca);
    $tarefas= array();
    while($tarefa =  mysqli_fetch_assoc($resultado)) 
    {
        $tarefas[] = $tarefa;
    }
    return $tarefas;
}
?>

Código HTML:
<?php
session_start();
include "tarefas.php";
?>
<!DOCTYPE html>
<html>
<head>
    <title>Tarefas</title>
    <link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<center><form method="GET">
    <fieldset id="felipe">
        <legend>Nova tarefa</legend>
        <label>Nome
            <input class="theme" type="text" name="nome">
        </label><br>
        <label>descrição
            <textarea class="themee" name="descricao"></textarea>
        </label><br>
        <label>Prazo
            <input class="theme" type="text" name="prioridade">
        </label><br>
        <fieldset id="felipee">
            <legend>Prioridade</legend>
        <label>
            <input type="radio" name="alta">Alta
            <input type="radio" name="media">Média
            <input type="radio" name="baixa">Baixa
        </label><br>
        </fieldset><br>
        <input type="submit" name="enviar">
    </fieldset>
</form></center>
     <table border='1px'>
        <tr>
            <td>Nome</td>
            <td>descricao</td>
            <td>prioridade</td>
        </tr>
        <tr>
            <td><?php print_r($tarefas)
            ?></td>
        </tr>
     </table>
</body>
</html>

How can I fix this error?

    
asked by anonymous 02.07.2018 / 23:55

1 answer

5

I think it should be in the place of this:

 <td><?php print_r($tarefas)
        ?></td>

This:

 <td><?php
   $tarefas = busca_tarefas($conexao);
   print_r($tarefas);
   ?></td>

As far as I understand functions do not run on their own and the variable $ tasks is within scope and return , ie it has to pass to a variable outside the scope of the function, $tarefas = .

It seems to me that it was either typo on your part or lack of understanding the basics of what a function is.

    
03.07.2018 / 00:09