-4
Why don’t you do UPDATE
in the database? The code does not give error but does not update.
<?php
elseif ($op === "atualizar")
{
//Atualizar arquivos
$id = $_POST["id"];
$nome = trim($_POST["nome"]);
$tipo = $_POST["tipo"];
if ($nome == "")
{
$mensagem = "O campo deve ser preenchido";
}
else
{
$sql = "UPDATE veiculo SET nome = '$nome', tipo = $tipo ";
$result = mysql_query($sql, $conn);
if ($result)
{
header("location:veiculoLista.php");
exit;
}
else $mensagem = "Não foi possível atualizar. Verifique os dados!";
}
}
?
<html>
<head>
<title>Veiculo cadastro</title>
</head>
<body>
<h1>Cadastro de veiculo </h1>
<font color="red"><?php if(isset($mensagem)) echo($mensagem);?></font>
<form method="post" action="veiculo.php" name="fveiculo">
<label>Nome</label><br />
<input name="nome" type="text" value="<?php echo $nome; ?>" size="45"/>
<br />
<label>Tipo</label>
<br />
<select name="tipo" size="1">
<option value="1" <?php if($tipo == 1) echo " selected"; ?>>Basico</option>
<option value="2" <?php if($tipo == 2) echo " selected"; ?>>Avancado com opcionais</option>
</select><br />
<?php if($op != "cadastrar"){?>
<input type="checkbox" name="excluir" value="excluir">Excluir<br>
<?php }?>
<?php if($op == "atualizar"){?>
<input type="hidden" name="id" value="<?php echo $id ?>">
<?php }?>
<input type="hidden" name="op" value="<?php echo $op ?>">
<input type="submit" value="Salvar"/>
<br />
<a href="javascript:void(null);" onclick="location.href='veiculoLista.php';">Voltar</a>
</form>
</body>
</html>
What is the specific problem you have? What error does it make? So it is difficult to help you.
– Jorge B.
The code appears to be incomplete, put the rest before "Else if". And be more objective in your question, read here http://answall.com/help/how-to-ask
– user28595
When you spin your code it falls into the
if($result)
or in theelse
?– feresjorge
The strange thing is code start with a
elseif
. So, what is the question exactly ? Because you can’t understand much. The form is filled with information in advance registered in the database ? Or simply record new information as your headers ? Explain better what you intend to do.– Edilson
It’s just an excerpt from the code
– Everson Souza de Araujo