Quantcast
Channel: Últimos conteúdos
Viewing all articles
Browse latest Browse all 14190

Duvida em relação em CRUD

$
0
0

Boa tarde,desculpe se estou no local errado,não sou acostumado com foruns..

 

estou com um projeto para minha empresa para controle de aparelhos vendidos,quero as funções de adicionar,editar e deletar(CRUD)

 

so que o meu codigo está colocando o ID para a ultima coluna e não esta colocando o primeiro campo que é o APARELHO.

Na pagina de edição está com um erro e fala que é na linha 7,eu nao consegui encontrar esse erro.

 

Pagina index:

<?php
include_once 'dbconfig.php';

// delete condition
if(isset($_GET['delete_id']))
{
 $sql_query="DELETE FROM cadastro WHERE user_id=".$_GET['delete_id'];
 mysql_query($sql_query);
 header("Location: $_SERVER[PHP_SELF]");
}
// delete condition
?>

<!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>CADASTRO DE APARELHOS</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript">
function edt_id(id)
{
 if(confirm('Sure to edit ?'))
 {
  window.location.href='edit_data.php?edit_id='+id;
 }
}
function delete_id(id)
{
 if(confirm('Sure to Delete ?'))
 {
  window.location.href='index.php?delete_id='+id;
 }
}
</script>
</head>
<body>
<center>

<div id="header">
 <div id="content">
    <label>CADASTRO DE APARELHOS</label>
    </div>
</div>

<div id="body">
 <div id="content">
    <table width="82%" align="center">
    <tr>
    <th colspan="9"><a href="add_data.php">ADICIONE DADOS AQUI.</a></th>
    </tr>
    <tr>
      <th width="20%">APARELHO</th>
      <th width="21%">COMPRADOR</th>
      <th width="21%">FONE</th>
      <th width="21%">ORIGEM</th>
    <th width="21%">DATA</th>
    <th width="42%">NEGOCIAÇÃO</th>
    <th width="42%">TOTAL</th>
    <th colspan="2">Operação</th>
    </tr>
    <?php
 $sql_query="SELECT * FROM cadastro";
 $result_set=mysql_query($sql_query);
 while($row=mysql_fetch_row($result_set))
 {
  ?>
        <tr>
        <td><?php echo $row[1]; ?></td>
        <td><?php echo $row[2]; ?></td>
        <td><?php echo $row[3]; ?></td>
        <td><?php echo $row[4]; ?></td>
        <td><?php echo $row[5]; ?></td>
        <td><?php echo $row[6]; ?></td>
        <td><?php echo $row[7]; ?></td>
  <td width="7%" align="center"><a href="javascript:edt_id('<?php echo $row[0]; ?>')"><img src="b_edit.png" align="EDIT" /></a></td>
        <td width="10%" align="center"><a href="javascript:delete_id('<?php echo $row[0]; ?>')"><img src="b_drop.png" align="DELETE" /></a></td>
        </tr>
        <?php
 }
 ?>
    </table>
    </div>
</div>

</center>
</body>
</html>

Pagina de inserção:

<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-save']))
{
 // variables for input data
 $aparelho = $_POST['aparelho'];
 $comprador = $_POST['comprador'];
 $fone = $_POST['fone'];
 $origem = $_POST['origem'];
 $data = $_POST['data'];
 $negociacao = $_POST['negociacao'];
 $total = $_POST['total'];
 // variables for input data

 // sql query for inserting data into database
 $sql_query = "INSERT INTO cadastro(aparelho,comprador,fone,origem,data,negociacao,total) VALUES('$aparelho','$comprador','$fone','$origem','$data','$negociacao','$total')";
 // sql query for inserting data into database
 
 // sql query execution function
 if(mysql_query($sql_query))
 {
  ?>
  <script type="text/javascript">
  alert('Data Are Inserted Successfully ');
  window.location.href='index.php';
  </script>
  <?php
 }
 else
 {
  ?>
  <script type="text/javascript">
  alert('error occured while inserting your data');
  </script>
  <?php
 }
 // sql query execution function
}
?>
<!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>CRUD Operations With PHP and MySql - By Cleartuts</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>

<div id="header">
 <div id="content">
    <label>CRUD Operations With PHP and MySql - By Cleartuts</label>
    </div>
</div>
<div id="body">
 <div id="content">
    <form method="post">
    <table align="center">
    <tr>
    <td align="center"><a href="index.php">VOLTAR</a></td>
    </tr>
    <tr>
    <td><input type="text" name="aparelho" placeholder="APARELHO" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="comprador" placeholder="COMPRADOR" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="fone" placeholder="FONE" required /></td>
    </tr>
     <tr>
    <td><input type="text" name="origem" placeholder="ORIGEM" required /></td>
    </tr>
     <tr>
    <td><input type="text" name="data" placeholder="DATA" required /></td>
    </tr>
     <tr>
    <td><input type="text" name="negociacao" placeholder="NEGOCIACAO" required /></td>
    </tr>
      <tr>
    <td><input type="text" name="negociacao" placeholder="TOTAL" required /></td>
    </tr> 
    <tr>
    <td><input type="text" name="total" placeholder="ID" required /></td>
    </tr>
    <tr>
    <td><button type="submit" name="btn-save"><strong>SALVAR</strong></button></td>
    </tr>
    </table>
    </form>
    </div>
</div>

</center>
</body>
</html>

Pagina de edição:

<?php
include_once 'dbconfig.php';
if(isset($_GET['edit_id']))
{
 $sql_query="SELECT * FROM cadastro WHERE id=".$_GET['edit_id'];
 $result_set=mysql_query($sql_query);
 $fetched_row=mysql_fetch_array($result_set);
}
if(isset($_POST['btn-update']))
{
 // variables for input data
 $aparelho = $_POST['aparelho'];
 $comprador = $_POST['comprador'];
 $fone = $_POST['fone'];
 $origem = $_POST['origem'];
 $data = $_POST['data'];
 $negociacao = $_POST['negociacao'];
 $total = $_POST['total'];
 // variables for input data

 // sql query for update data into database
 $sql_query = "UPDATE cadastro SET aparelho='$aparelho',comprador='$comprador',fone='$fone',origem='$origem',data='$data',negociacao='$negociacao',total='$total' WHERE id=".$_GET['edit_id'];
 // sql query for update data into database
 
 // sql query execution function
 if(mysql_query($sql_query))
 {
  ?>
  <script type="text/javascript">
  alert('Data Are Updated Successfully');
  window.location.href='index.php';
  </script>
  <?php
 }
 else
 {
  ?>
  <script type="text/javascript">
  alert('error occured while updating data');
  </script>
  <?php
 }
 // sql query execution function
}
if(isset($_POST['btn-cancel']))
{
 header("Location: index.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>CADASTRO DE APARELHOS</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>

<div id="header">
 <div id="content">
    <label>CADASTRO DE APARELHOS</label>
    </div>
</div>

<div id="body">
 <div id="content">
    <form method="post">
    <table align="center">
    <tr>
    <td><input type="text" name="aparelho" placeholder="APARELHO" value="<?php echo $fetched_row['aparelho']; ?>" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="comprador" placeholder="COMPRADOR" value="<?php echo $fetched_row['comprador']; ?>" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="fone" placeholder="FONE" value="<?php echo $fetched_row['fone']; ?>" required /></td>
    </tr>
      <tr>
    <td><input type="text" name="origem" placeholder="ORIGEM" value="<?php echo $fetched_row['origem']; ?>" required /></td>
    </tr>
      <tr>
    <td><input type="text" name="data" placeholder="DATA" value="<?php echo $fetched_row['data']; ?>" required /></td>
    </tr>
      <tr>
    <td><input type="text" name="negociacao" placeholder="NEGOCIAÇÃO" value="<?php echo $fetched_row['negociacao']; ?>" required /></td>
    </tr>
      <tr>
    <td><input type="text" name="total" placeholder="TOTAL" value="<?php echo $fetched_row['total']; ?>" required /></td>
    </tr>
    <tr>
    <td>
    <button type="submit" name="btn-update"><strong>ATUALIZAR</strong></button>
    <button type="submit" name="btn-cancel"><strong>CANCELAR</strong></button>
    </td>
    </tr>
    </table>
    </form>
    </div>
</div>

</center>
</body>
</html>

gostaria muito da ajuda de vocês,assim que eu terminar esse codigo vou estar fazendo uma pagina para login,assim só eu e meu socio vizualizaremos os dados.


Viewing all articles
Browse latest Browse all 14190