List/Menu - PHP
boa tarde a todos...amigos, mais um problema, estou adicionando dados, porem um valor no List/Menu não muda, é como se estivesse marcado como default, para melhor entender:
a operação de atualizar é assim:
<?php
include ("conexao.php");
$acao = @$_GET["acao"];
$id = @$_GET["id"];
if ($acao != "")
{
$sql = "SELECT c.*, s.* FROM categoria c, subcategoria s WHERE c.id_categoria = s.id_categoria and id_subcategoria = '$id' ";
$qry = mysql_query($sql);
$linha = mysql_fetch_array($qry);
$subcategoria = $linha[@subcategoria];
$id_categoria = $linha[@id_categoria];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">Cadastro de Categorias </div></td>
</tr>
<tr>
<td><form id="form1" name="form1" method="post" action="op_subcategoria.php">
<table width="314" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>Categoria</td>
<td><label>
<select name="id_categoria" id="id_categoria">
<option>Selecione uma categoria</option>
<?php
$sql = "SELECT * FROM categoria ORDER BY categoria";
$qry = mysql_query($sql);
while (@$linha = mysql_fetch_array($qry)){
$valor = $linha[@id_categoria];
if ($id_categoria = $valor)
{
$selecionado = "selected";
}
else
{
$selecionado ="";
}
echo "<option value = \"$valor\" $selecionado > $linha[categoria] </option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td>SubCategoria</td>
<td width="211"><input name="txt_subcategoria" type="text" id="txt_subcategoria" value="<?php echo @$subcategoria; ?>" size="35" /></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit" value="<?php if($acao != ""){echo $acao;}else {echo "Inserir";}?>" />
<input name="acao" type="hidden" id="acao" value="<?php if($acao != ""){echo $acao;}else {echo "Inserir";}?>" />
<input name="id" type="hidden" id="id" value="<?php echo $id; ?>" />
</div>
</label></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
a operação de atualizar é assim:
if ($acao == Alterar)
{
$sql = "UPDATE subcategoria SET
id_categoria = '$id_categoria',
subcategoria = '$txt_subcategoria'
WHERE id_subcategoria = '$id' ";
mysql_query($sql) or die ("Não foi possivel alterar os dados");
echo "<script type = 'text/javascript'> location.href='index.php?link=4'</script>";
}
Marcio Araujo
Curtidas 0
Respostas
Marcio Araujo
08/01/2013
a operação de inserir
if ($acao == "Inserir")
{
$sql = "INSERT INTO subcategoria (id_categoria, subcategoria) VALUES ('$id_categoria','$txt_subcategoria')";
mysql_query($sql) or die ("Não foi possivel inserir os dados");
echo "<script type = 'text/javascript'> location.href='index.php?link=4'</script>";
}
GOSTEI 0
Eduardo Pessoa
08/01/2013
alguem sabe o caminho???
GOSTEI 0
Marcio Araujo
08/01/2013
alguem poderia me ajudar???
GOSTEI 0
William
08/01/2013
Marcio o que seria esse "List/Menu" ?
GOSTEI 0
Marcio Araujo
08/01/2013
desculpa, é que estou utilizando o dreamweaver, bom esse list/menu é o list box...
GOSTEI 0
Marcio Araujo
08/01/2013
e aew sabe???
GOSTEI 0
William
08/01/2013
Fiz algumas alterações no seu código, aparentemente está funcionando.
1 - Alterei um pouco sua instrução SQL;
2 - Sua condição if estava com apenas 1 sinal de "=";
Qualquer coisa posta aí ...
1 - Alterei um pouco sua instrução SQL;
2 - Sua condição if estava com apenas 1 sinal de "=";
<?php
include ("conexao.php");
$acao = @$_GET["acao"];
$id = @$_GET["id"];
if ($acao != "")
{
$sql = "SELECT c.id_categoria, s.subcategoria FROM categoria c INNER JOIN subcategoria s ON c.id_categoria = s.id_categoria and id = '$id' ";
$qry = mysqli_query($conexao, $sql);
$linha = mysqli_fetch_array($qry);
$subcategoria = $linha['subcategoria'];
$id_categoria = $linha['id_categoria'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">Cadastro de Categorias </div></td>
</tr>
<tr>
<td><form id="form1" name="form1" method="post" action="op_subcategoria.php">
<table width="314" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>Categoria</td>
<td><label>
<select name="id_categoria" id="id_categoria">
<option>Selecione uma categoria</option>
<?php
$sql = "SELECT * FROM categoria ORDER BY categoria";
$qry = mysqli_query($conexao, $sql);
while ($linha = mysqli_fetch_array($qry)){
$valor = $linha['id_categoria'];
if ($id_categoria == $valor)
{
$selecionado = "selected";
}
else
{
$selecionado ="";
}
echo "<option value = \"$valor\" $selecionado>".$linha['categoria'] ."</option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td>SubCategoria</td>
<td width="211"><input name="txt_subcategoria" type="text" id="txt_subcategoria" value="<?php echo @$subcategoria; ?>" size="35" /></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit" value="<?php if($acao != ""){echo $acao;}else {echo "Inserir";}?>" />
<input name="acao" type="hidden" id="acao" value="<?php if($acao != ""){echo $acao;}else {echo "Inserir";}?>" />
<input name="id" type="hidden" id="id" value="<?php echo $id; ?>" />
</div>
</label></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
Qualquer coisa posta aí ...
GOSTEI 0
William
08/01/2013
Observação alterei as funções para mysqli, mas pode voltar para mysql!
GOSTEI 0
Marcio Araujo
08/01/2013
vou verificar...depois te dou um retorno
GOSTEI 0
Marcio Araujo
08/01/2013
Observação alterei as funções para mysqli, mas pode voltar para mysql!
não entendi, essa parte.
GOSTEI 0
William
08/01/2013
É seguinte, por exemplo:
Você executa sua querys assim:
Eu executo com outro tipo de função:
Note a diferença entre "mysql" e "mysqli"!
As funções "mysqli" foram implementadas mais recentemente pelo PHP, e trázem algumas funcionalidades a mais que o "mysql", blz?
Você executa sua querys assim:
$qry = mysql_query($sql);
Eu executo com outro tipo de função:
$qry = mysqli_query($conexao, $sql);
Note a diferença entre "mysql" e "mysqli"!
As funções "mysqli" foram implementadas mais recentemente pelo PHP, e trázem algumas funcionalidades a mais que o "mysql", blz?
GOSTEI 0
Marcio Araujo
08/01/2013
blz wllfl, entendi...
assim que tiver algum resultado, te aviso
obrigado mais uma vez...
assim que tiver algum resultado, te aviso
obrigado mais uma vez...
GOSTEI 0
Marcio Araujo
08/01/2013
hahahahahaha
eu iria morrer doido e não saberia...kkkkkkkkkkkk
era só o "==" tinha só um...
MUITO OBRIGADO!!!
eu iria morrer doido e não saberia...kkkkkkkkkkkk
era só o "==" tinha só um...
MUITO OBRIGADO!!!
GOSTEI 0
José
08/01/2013
Marcio obrigado pelo retorno, e já que sua duvida foi solucionada.
Estou dando este tópico por concluído.
Estou dando este tópico por concluído.
GOSTEI 0