Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

EDITAR BANCO APARTIR DO ID

OLA PESSOAL nao consigo editar um banco de dados a partir do id, primeiro que o transporte da variavel nao esta indo o id correto, preciso pegar a variavel e exibir para edicao somente a linha expecifica

LISTAR.PHP

<?php include("conexao.php"); ?>

<?php
//Selecionar todos os produtos da tabela
$result_produtos = "SELECT * FROM intranetacontece ORDER BY id DESC";
$resultado = mysqli_query($mysqli, $result_produtos);
?>




<!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>Metalsystem</title>

<link href="java/css/bootstrap.min.css" rel="stylesheet">
<script src="java/js/jquery.js"></script>
<script src="java/js/bootstrap.min.js"></script>


</head>
<body>
<table width="822" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="818" height="95">


<form id="form1" name="form1" method="post" action="02acontece_editar.php">

<?php while($row = mysqli_fetch_array($resultado)){
$id = $row['id'];
$foto = $row['foto'];
$descricao = $row['descricao'];
?>
<table width="803" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="87" height="59"><?php echo $id ?>
      <input name="id_acontece" type="hidden" id="id_acontece" value="<?php echo $id ?>" /></td>
    <td width="193"><?php echo $foto ?></td>
    <td width="161" align="left"><?php echo $descricao ?></td>
    <td width="288"><img src="../img/<?php echo $row['foto'];?>.jpg" alt="..." width="49" height="57" /></td>
    <td width="62"><input type="submit" name="button" id="button" value="editar" /></td>
    <td width="62"><input type="submit" name="button2" id="button2" value="excluir" /></td>
    <td width="62"> </td>
  </tr>
</table>
 <?php } ?>


</form>


</td>
  </tr>
</table>
</body>
</html>
2 respostas
EDITAR.PHP



<!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>



<?php

$hostname_conexao = "localhost";
$database_conexao = "metal";
$username_conexao = "root";
$password_conexao = "";

$mysqli = new mysqli($hostname_conexao, $username_conexao, $password_conexao, $database_conexao);
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

$id = $_POST['id_acontece'];


$sql = mysql_query("SELECT * FROM intranetacontece WHERE id =  '".$_POST['id_acontece']."' ");

$row = mysql_fetch_array($sql);

$foto = $row['foto'];
$descricao = $row['descricao'];
$id = $row['id'];

?>
<form id="form1" name="form1" method="post" action="salvar.php">
<table width="400" border="0" align="center">
<tr><td width="1">Empresa:</td>
<td width="400"><input name="empresa" type="text" size="50" id="id" maxlength="100" value="<?php echo $row["id"]; ?>" /></td>
</tr>

<tr><td width="1">Endereço:</td>
<td width="400"><input name="endereço" type="text" size="50" id="foto" maxlength="100" value="<?php echo $row["foto"]; ?>" /></td>
</tr>

<tr><td width="1">Bairro:</td>
<td width="400"><input name="bairro" type="text" size="50" id="descricao" maxlength="100" value="<?php echo $row["descricao"]; ?>" /></td>
</tr>
<tr><td>
  <input type="submit" name="submit" value="Salvar"></td>
</tr>
</table>
</form>




</body>
</html>
solução!

Neste caso você precisa de um FORM para cada item da lista. Altere a sua lista para ficar da seguinte forma:

<?php while($row = mysqli_fetch_array($resultado)){
    $id = $row['id'];
    $foto = $row['foto'];
    $descricao = $row['descricao'];
?>
<table width="803" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="87" height="59"><?php echo $id ?>

    <td width="193"><?php echo $foto ?></td>
    <td width="161" align="left"><?php echo $descricao ?></td>
    <td width="288"><img src="../img/<?php echo $row['foto'];?>.jpg" alt="..." width="49" height="57" /></td>
    <td width="62">
        <form id="form1" name="form1" method="post" action="02acontece_editar.php">
            <input type="submit" name="button" id="button" value="editar" />
            <input name="id_acontece" type="hidden" value="<?php echo $id ?>" /></td>
        </form>
    </td>
    <td width="62">
        <form id="form1" name="form1" method="post" action="pagina_de_excluir.php">
            <input type="submit" name="button2" id="button2" value="excluir" />
            <input name="id_acontece" type="hidden" value="<?php echo $id ?>" /></td>
        </form>
    </td>
    <td width="62"> </td>
  </tr>
</table>
 <?php } ?>

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software