Erro Undefined index: Alguem pode me ajudar pls?
galera alguem pode me ajudar vou mandar a imagem e o codigo
esse e o erro:
aqui ta o codigo
tarefas.php:
<?php session_start();?>
<html>
<head>
<title>Gerenciador de tarefas</title>
<!--<link rel="stylesheet" href="tarefas.css">-->
</head>
<body>
<h1>Gerenciador de tarefas</h1>
<form>
<fieldset>
<legend> Nova tarefa</legend>
<label>
Tarefa:
<input type="text" name="nome" />
</label>
<input type="submit" value="Cadastrar" />
</fieldset>
</form>
<?php
if(array_key_exists('nome', $_GET)){
$_SESSION['lista_tarefas'][]=$_GET['nome'];
}
$lista_tarefas = [];
if (array_key_exists('lista_tarefas', $_SESSION)){
$lista_tarefas = $_SESSION['lista_tarefas'];
}
?>
<table>
<tr>
<td>Tarefas</td>
</tr>
<?php foreach ($lista_tarefas as $tarefa ): ?>
<tr>
<td> <?php echo $tarefa; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
tabela.php:
<html>
<head>
<meta charset="utf-8"/>
<title>Gerenciador de Tarefas</title>
<link rel="stylesheet" type="text/css" href="tarefas.css">
</head>
<body>
<table>
<tr>
<th>Tarefas</th>
<th>Descrição</th>
<th>Prazo</th>
<th>Prioridade</th>
<th>Concluida</th>
<th>Opções</th>
</tr>
<?php // foreach e uma repetição
foreach ($lista_tarefas as $tarefa): ?>
<tr>
<td> <?php echo $tarefa['nome'];?></td>
<td> <?php echo $tarefa['descricao'];?></td>
<td> <?php echo traduz_data_para_exibir($tarefa['prazo']);?></td>
<td><?php echo traduz_prioridade($tarefa['prioridade']); ?></td>
<td> <?php echo traduz_concluida( $tarefa['concluida']);?> </td>
<td><a href="editar.php?id=<?php echo $tarefa['id']; ?>">Editar</a></tr>
<?php endforeach; ?>
</table>
</body>
</html>
template.php:
<html>
<head>
<meta charset="utf-8"/>
<title>Gerenciador de Tarefas</title>
<link rel="stylesheet" type="text/css" href="tarefas.css">
</head>
<body>
<?php require 'formulario.php';?>
<?php if($exibir_tabela) : ?>
<?php require 'tabela.php';?>
<?php endif;?>
</body>
</html>
banco.php:
<?php
$bdServidor = '127.0.0.1:3307';
$bdUsuario = 'root';
$bdSenha = '';
$bdBanco = 'tarefas';
//
$conexao = mysqli_connect($bdServidor, $bdUsuario, $bdSenha, $bdBanco);
if (mysqli_connect_errno($conexao)){
echo "problema para conectar ao banco. Erro: ";
echo mysqli_connect_error();
die();
}
function buscar_tarefas($conexao){
$sqlBusca = 'SELECT * FROM tarefas';
$resultado = mysqli_query($conexao, $sqlBusca);
$tarefas = [];
while ($tarefa = mysqli_fetch_assoc($resultado)){
$tarefas[] = $tarefa;
}
return $tarefas;
}
function gravar_tarefa($conexao, $tarefa)
{
$sqlGravar=" INSERT INTO tarefas(nome, descricao,prioridade,prazo,concluida)
values(
'{$tarefa['nome']}',
'{$tarefa['descricao']}',
'{$tarefa['prioridade']}'
'{$tarefa['prazo']}'
'{$tarefa['concluida']}'
)";
function buscar_tarefa($conexao, $id){
$sqlBusca = 'SELECT * FROM tarefas WHERE id = '. id;
$resultado = mysql_query($conexao, $sqlBusca);
return mysqli_fetch_assoc($resultado);
}
function editar_tarefa($conexao, $tarefa){
$sqlEditar = "
UPDATE tarefas SET
nome='{$tarefa['nome']}',
descricao'{$tarefa['descricao']}',
prioridade'{$tarefa['prioridade']}',
prazo'{$tarefa['prazo']}',
concluida'{$tarefa['concluida']}',
WHERE id = {$tarefa['id']}
";
}
mysqli_query ($conexao, $sqlGravar);
}
?>
index.php:
<?php session_start();
require "banco.php";
require "utilitarios.php";
$exibir_tabela = true;
if (array_key_exists('nome', $_GET) && $_GET['nome'] != ''){
$tarefa = [];
$tarefa['nome'] = $_GET['nome'];
if (array_key_exists('descricao', $_GET)){
$tarefa['descricao'] = $_GET['descricao'];
}
else{
$tarefa['descricao'] = '';
}
if ( array_key_exists('prazo', $_GET)){
$tarefa['prazo']= traduz_data_para_banco($_GET['prazo']);
} else{
$tarefa['prazo'] = '';
}
$tarefa ['prioridade'] = $_GET['prioridade'];
if ( array_key_exists('concluida', $_GET)){
$tarefa['concluida']=1;
} else{
$tarefa['concluida'] = 0;
}
gravar_tarefa($conexao, $tarefa);
}
$lista_tarefas = buscar_tarefas($conexao);
$tarefa=[
'id' =>0,
'nome' =>'',
'descricao' =>'',
'prazo' =>'',
'prioridade' =>3,
'concluida' =>''
];
include "template.php";
?>
utilitarios.php:
<?php
function traduz_prioridade($codigo)
{
$prioridade='';;
switch($codigo){
case 1:
$prioridade='Baixa';
break;
case 2:
$prioridade='Media';
break;
case 3:
$prioridade='Alta';
break;
}
return $prioridade;
}
function traduz_data_para_banco($data){
if($data == ""){
return "";
}
$dados = explode("/", $data);
$data_banco = "{$dados[2]}-{$dados[1]}-{$dados[0]}";
return $data_banco;
}
function traduz_data_para_exibir($data){
if($data == "" OR $data == "0000-00-00"){
return "";
}
$dados = explode("-", $data);
$data_exibir = "{$dados[2]}/{$dados[1]}/{$dados[0]}";
return $data_exibir;
}
function traduz_concluida($concluida){
if($concluida == 1){
return 'sim';
}
return 'Não';
}
?>
formulario.php:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf=8" />
<title>Gerenciador de tarefas</title>
<link rel="stylesheet" type="text/css" href="tarefas.css">
</head>
<body>
<h1>Gerenciador de Tarefas</h1>
<form>
<input type="hidden" name="id"
value="<?php echo $tarefa['id'];?>"/>
<fieldset>
<legend>Nova Tarefa</legend>
<label>
Tarefa:
<input type="text" name="nome"
value= "<?php echo $tarefa['nome'];?>" />
</label>
<label>
Descrição:
<textarea name="descricao" > <?php echo $tarefa['descricao'];?></textarea>
</label>
<label>
Prazo:
<input type="text" name="prazo"
value="<?php echo traduz_data_para_exibir($tarefa['prazo']);?>"/>
</label>
<fieldset>
<legend>Prioridade</legend>
<label>
<input type= "radio" name="prioridade" value="1" <?php echo ($tarefa['prioridade']==1) ? 'checked': '';?>/> Baixa
<input type="radio" name="prioridade" value="2" <?php echo ($tarefa['prioridade']==2) ? 'checked': '';?> /> Media
<input type="radio" name="prioridade" value="3" <?php echo ($tarefa['prioridade']==3) ? 'checked': '';?>/> Alta
</label>
</fieldset>
<label>
Tarefa Concluida:
<input type="checkbox" name="Concluida" value="1"<?php echo ($tarefa['concluida']==1) ? 'checked': '';?> />
</label>
<input type ="submit" value="<?php echo ($tarefa['id'] > 0) ? 'atualizar': 'Cadastrar';?> "/>
</body>
</html>
editar.php:
<?php session_start();
require "banco.php";
require "utilitarios.php";
$exibir_tabela = false;
if (array_key_exists('nome', $_GET) && $_GET['nome'] != ''){
$tarefa = [];
$tarefa['id']= $_GET['id'];
$tarefa['nome'] = $_GET['nome'];
if (array_key_exists('descricao', $_GET)){
$tarefa['descricao'] = $_GET['descricao'];
}
else{
$tarefa['descricao'] = '';
}
if ( array_key_exists('prazo', $_GET)){
$tarefa['prazo']= traduz_data_para_banco($_GET['prazo']);
} else{
$tarefa['prazo'] = '';
}
$tarefa ['prioridade'] = $_GET['prioridade'];
if ( array_key_exists('concluida', $_GET)){
$tarefa['concluida']=1;
} else{
$tarefa['concluida'] = 0;
}
editar_tarefa($conexao, $tarefa);
header('Location: index.php');
die();
}
$tarefa = buscar_tarefas($conexao,$_GET['id']);
include "template.php";
?>Discussão (6)
Carregando comentários...