Why is my table in mysql not updated using php?

0

I've been trying to update a mysql table that I have on phpmyadmin without success. The data that I enter to update this table if they manage to be sent by the POST method to another php page but can not be updated in the table. While you set default values in the variables, the query does update the data in the mysql table.

PHP where I choose the name and enter the nationality I want to edit in the table:

<div style="display:">

  <?php

  	$mysqli=new mysqli("localhost","root","","bdlicitaciones"); //servidor, usuario de base de datos, contraseña del usuario, nombre de base de datos

  	if(mysqli_connect_errno()){
  		echo 'Conexion Fallida : ', mysqli_connect_error();
  		exit();
  	}

  ?>




  <?php

  /*
   * Código para mostrar datos dinámicamente en un combobox.
   */


  $query = 'SELECT * FROM oferentes';

  $result = $mysqli->query($query);

  ?>
  <div class="row ">
    <div class="input-field col s12 m10 l10">
    <p style="text-align:left;"> ID del Oferente:</p>
    <select  id="IDOferente" class="browser-default col s12 m10 l10" name="IDOferente">

      <?php
      while ( $row = $result->fetch_array() )
      {
          ?>


       <option value=" <?php echo $row['ID_Oferente'] ?> " >
         <?php echo $row['ID_Oferente']; ?>

       </option>

       <?php
   }
   ?>
    </select>
    </div>
  </div>




</div>

HTML>
<HEAD>
<TITLE>Actualizar1.php</TITLE>
</HEAD>
<BODY>
<div align="center">
<h1>Actualizar un registro</h1>
<br>

<form class="col s12 m12 l12 " action="prueba4.php" method="post" name="forminsertar" id="forminsertar">

  <?php

  $query = 'SELECT NombreOferente FROM oferentes';

  $result = $mysqli->query($query);


   ?>

   <div class="row ">
     <div class="input-field col s12 m10 l10">
     <p style="text-align:left;"> ID del Oferente:</p>
     <select  id="oferentes2" class="browser-default col s12 m10 l10" name="oferentes2" >

       <?php
       while ( $row = $result->fetch_array() )
       {
           ?>


        <option value=" <?php echo $row['NombreOferente'] ?> " >
          <?php echo $row['NombreOferente']; ?>

        </option>

        <?php
    }
    ?>
     </select>

     <br>
Nacionalidad<br>
<INPUT id="nacionalidad" TYPE="TEXT" NAME="nacionalidad"><br>
<INPUT TYPE="SUBMIT" value="Actualizar">

 
</FORM>
</div>


</BODY>
</HTML>

PHP to which the form is sent and in which the query that should update the table is executed

<div style="display:">

  <HTML>
  <HEAD>
  <TITLE>Actualizar2.php</TITLE>
  </HEAD>
  <BODY>

<?php

$nacionalidad1 = $_POST['nacionalidad'];
?>
<?php

$nombre = $_POST['oferentes2'];

 ?>

  <?php

  	$mysqli=new mysqli("localhost","root","","bdlicitaciones"); //servidor, usuario de base de datos, contraseña del usuario, nombre de base de datos

  	if(mysqli_connect_errno()){
  		echo 'Conexion Fallida : ', mysqli_connect_error();
  		exit();
  	}







   $sql="UPDATE oferentes SET Nacionalidad='$nacionalidad1' WHERE NombreOferente='$nombre'";
   $rs =mysqli_query($mysqli,$sql);
   if($rs){

       echo "Records inserted successfully.";

   } else{

       echo "ERROR: Could not able to execute $sql. " . mysqli_error($mysqli);

   }

   mysqli_close($mysqli);
?>



<h1><div align="center">Registro Actualizado</div></h1>
<div align="center"><a href="lectura.php">Visualizar el contenido de la base</a></div>

</BODY>
</HTML>
    
asked by Rodriguez1222 04.05.2018 в 17:51
source

0 answers