Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Eaí Galera beleza?
estou com uma duvida alguem poderia me ajudar?
Eu tenho 2 tabelas no meu banco de dados, a primeira eu tenho (Nome, Email, Empresa, Telefone, Cidade) e na outra tabela eu tenho os Telefones dos usuario, pelo seguinte, cada usuario pode ter por exemplo 10 telefones, ae eu criei uma tabela só para guardar os telefones, e relacionei as 2 tabelas pra eu saber de quem pertence o telefone.
ae pra editar a primeira tabela eu fiz assim:
include("conexao.php");
$id = intval($_GET["id"]);
if($id)
{
$rs = executar("SELECT * FROM tformulario WHERE ID = '".$id."' ");
if(mysql_num_rows($rs) > 0)
{
$ar = mysql_fetch_row($rs);
$txtNome = $ar[1];
$txtEmail = $ar[2];
$txtEmpresa = $ar[3];
$txtCidade = $ar[4];
$cbNovidade = $ar[5];
}
else
{
$id = null;
}
}
if($_POST)
{
$txtNome = $_POST["txtNome"];
$txtEmail = $_POST["txtEmail"];
$txtEmpresa = $_POST["txtEmpresa"];
$txtTelefone = $_POST["txtTelefone"];
$txtCidade = $_POST["txtCidade"];
$cbNovidade = $_POST["cbNovidade"];
if($id)
{
executar("UPDATE tformulario SET Nome = '$txtNome', Email = '$txtEmail', Empresa = '$txtEmpresa', Cidade = '$txtCidade', Novidade = '$cbNovidade' WHERE ID = '".$id."' ");
}
else
{
executar("INSERT INTO tformulario (Nome, Email, Empresa, Cidade, Novidade) VALUES ('$txtNome', '$txtEmail', '$txtEmpresa', '$txtCidade', '$cbNovidade')");
}
<?php
while ($row = mysql_fetch_array($rs))
{
?>
<tr>
<td><?php echo $row["ID"]; ?></td>
<td><?php echo $row["Nome"]; ?></td>
<td><?php echo $row["Email"]; ?></td>
<td><?php echo $row["Empresa"]; ?></td>
<td><?php echo $row["Cidade"]; ?></td>
<td><?php echo $row["Novidade"]; ?></td>
<td>| <a href="?id=<?php echo $row['ID']; ?>">Editar</a> | <a href="?remover=<?php echo $row['ID']; ?>" onclick="return confirm ('Tem certeza que deseja Remover?');">Remover</a></td>
</tr>
<?php
}
?>
e quando eu clico em 'Editar', as informações vai para este formulario ae eu consigo edita, mas e pra eu editar os telefones?? sendo que um usuario pode ter 10 telefones, e no meu formulario eu tenho apenas 1 campo de telefone?
<form action="" method="post" enctype="multipart/form-data" style="float: left;">
<label>
Nome:<br />
<input type="text" id="txtNome" name="txtNome" maxlength="150" size="50" title="Digite o nome." value="<?php echo $txtNome;?>" />
</label>
<br />
<label>
E-mail:<br />
<input type="text" id="txtEmail" name="txtEmail" maxlength="150" size="50" title="Digite o e-mail." value="<?php echo $txtEmail;?>" />
</label>
<br />
<label>
Empresa:<br />
<input type="text" id="txtEmpresa" name="txtEmpresa" maxlength="150" size="50" title="Digite a empresa." value="<?php echo $txtEmpresa;?>" />
</label>
<br />
<label>
Telefone: <br />
<input type="text" name="txtTelefone" maxlength="14" size="50" value="<?php echo $txtTelefone; ?>" />
</label>
<br />
<label>
Cidade:<br />
<input type="text" id="txtCidade" name="txtCidade" maxlength="50" size="50" title="Digite a cidade." value="<?php echo $txtCidade;?>" />
</label>
<br />
<label>
<div class="desejo">
<p>Desejo receber as novidades por e-mail.</p>
<input type="checkbox" name="cbNovidade" id="cbNovidade" value="1" checked="checked" />
</div>
</label>
<br />
<input type="submit" value="enviar" />
</form>
<form method="get" action="" style="float: left; margin-left: 100px;">
<table>
<tr>
<td align="center"><p><strong>Pesquisar:</strong></p></td>
</tr>
<tr>
<td align="right">
<label>
Nome:<input type="text" name="palavra" size="30" value="<?php echo $palavra;?>" />
</label>
</td>
</tr>
<tr>
<td align="right">
<label>
Cidade: <input type="text" name="cidade" size="30" value="<?php echo $cidade;?>" />
</label>
</td>
</tr>
<tr>
<td align="right">
<label>
Telefone: <input type="text" class="mask-telefone" name="fone" size="30" />
</label>
</td>
</tr>
<tr>
<td><input type="submit" value="buscar" /></td>
</tr>
</table>
</form>
Alguém tem alguma sugestão? Por favor!
Carregando comentários...