Pass input value hidden to another

0

Cordial greeting. I have the following, I am trying to insert in two different tables, in a very "simple" way, certain data. In the tables logistica_equipos_calibracion I have a field called id that works as an "index", since it is the same name of the station of the table logistica_equipos , the problem is that when I'm going to perform the insertion says that the id field can not be null.

if((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO logistica_equipos (id, CB) VALUES (%s, %s)",
                  GetSQLValueString($_POST['id'], "int"),
                  GetSQLValueString($_POST['CB'], "text"));

    $insertSQL2 = sprintf("INSERT INTO logistica_equipos_calibracion (id_cali, id, CB, MEDIDA1, MEDIDA2) VALUES (%s, %s, %s, %s)", 
                  GetSQLValueString($_POST['id_cali'], "int"),
                  GetSQLValueString($_POST['id2'], "int"),
                  GetSQLValueString($_POST['CB'], "text"),
                  GetSQLValueString($_POST['MEDIDA1'], "text"),
                  GetSQLValueString($_POST['MEDIDA2'], "text"));

      mysql_select_db($database_conexion, $conexion);
      $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());
      $Result2 = mysql_query($insertSQL2, $conexion) or die(mysql_error());
}

<input type="hidden" name="id2" id="id" value="id">
<input type="hidden" name="id" id="id">
<input type="hidden" name="MM_insert" value="form1">
    
asked by Anderviver 02.03.2018 в 23:08
source

1 answer

0

When you are working with relational databases you need to pass to the "daughter" table the id of the record to which you are going to relate, for example; if you create a record in table A, an id (incremental auto integer) will be generated in table B, information saved in table A, therefore you need the id generated in the first record (table A) PHP provides a method called mysql_insert_id which returns the id generated from the record that was saved from the last record that you inserted, that value must be passed to your table B in order to create the relationship correctly.

Read about the subject in this link: link

    
answered by 05.03.2018 / 03:53
source