无法更新我的数据库

时间:2015-04-03 03:57:25

标签: php mysqli sql-update database-connection

所以,我从另一个php获得了id_cliente,我从该ID中正确地得到了它。我想更新我的数据库,但我找不到办法。我已经尝试了UPDATE,我的一位朋友检查了代码是否存在语法错误,但我仍然想知道是否有任何使用错误。

这是我的身体:

<body>
  <div class="maindiv">

  <div class="form_div">
  <div class="title">
    <h2>Insertando datos a la tabla de Cliente.</h2>
  </div>
  <?php 
    $id_cliente = $_POST['id_cliente'];
  ?>
  <form action="actualizar.php" method="post">
        <?php 
                 $query= "SELECT * FROM cliente WHERE $id_cliente = id_cliente";
                    include "../conexion/conexion.php";
                    $sql = mysqli_query($conn, $query);
                    if(empty($sql)) echo "No se encontró ningún personal que coincida con la búsqueda";
                       else{
                     while($row = mysqli_fetch_object($sql)){   ?>
  <h2>Llena todos los campos.</h2>
    <label>Clave:</label>
    <input class="input" name="clave" type="number" value="<?php echo $row->CLAVE ?>">
    <label>Nombre:</label>
    <input class="input" name="nombre" type="text" value="<?php echo $row->NOMBRE ?>">
    <label>Apellido Paterno:</label>
    <input class="input" name="apellido_p" type="text" value="<?php echo $row->APELLIDO_P ?>">
    <label>Apellido Materno:</label>
    <input class="input" name="apellido_m" type="text" value="<?php echo $row->APELLIDO_M ?>">
    <label>Direccion:</label>
    <textarea cols="25" name="direccion" rows="5"><?php echo $row->DIRECCION ?></textarea><br>
    <label>Telefono:</label>
    <input class="input" name="telefono" type="text" value="<?php echo $row->TELEFONO ?>">
    <label>Correo:</label>
    <input class="input" name="correo" type="text" value="<?php echo $row->CORREO ?>">
    <label>Fecha de Nacimiento (AA/MM/DD):</label>
    <input class="input" name="fecha" type="date" value="<?php echo $row->NACIMIENTO ?>">
    <label>Saldo:</label>
    <input class="input" name="saldo" type="number" value="<?php echo $row->SALDO ?>">
            <?php } $conn->close(); } ?>
    <?php
     $connection = mysqli_connect("localhost", "root", "");
      $db = mysqli_select_db($connection,"cajadeahorros");
error_reporting(0);
      if(isset($_POST['submit']))
      {
        if($_POST['id_cliente'] == "") $_POST['id_cliente'] = "NULL";
        $clave = $_POST['clave'];
        $nombre = $_POST['nombre'];
        $apellido_p = $_POST['apellido_p'];
        $apellido_m = $_POST['apellido_m'];
        $direccion = $_POST['direccion'];
        $telefono = $_POST['telefono'];
        $correo = $_POST['correo'];
        $fecha = $_POST['fecha'];
        $saldo = $_POST['saldo'];

        $q="select count(1) from cliente where clave='$clave'";
        $r=mysqli_query($connection,$q);
        $row=mysqli_fetch_row($r);
        if($row[0]>=1)
        {
          $x = 1;
        }
        else
        {
          $x = 0;
        }

        if($clave !=''&&$nombre !=''&&$apellido_p !=''&&$apellido_m !=''&&$direccion !=''&&$telefono !=''&&$correo !=''&&$fecha !=''&&$saldo !=''&&$x==0)
        {
          $query = mysqli_query($connection, "update cliente set clave = 'a', nombre = 'a', apellido_p='a', apellido_m='a', direccion ='a', correo='a', nacimiento='a', saldo='a' where id_cliente = '$id_cliente'");
          echo "<br/><br/><span>Datos ingresados correctamente.</span>";
        }
        else
        {
          echo "<p>No se pudo insertar. <br/> Algunos campos estan vacios o la clave ya existe.</p>";
        }
      }

      mysqli_close($connection); 

    ?>
    <input class="submit" name="submit" type="submit" value="Insertar">

  </form>
  </div>
  </div>
</body>

1 个答案:

答案 0 :(得分:0)

请更改您提供的顶部选择查询

$query= "SELECT * FROM cliente WHERE $id_cliente = id_cliente";

$query= "SELECT * FROM cliente WHERE id_cliente = $id_cliente";
相关问题