Foros del Web » Programando para Internet » PHP »

formulario con campo incremental a peticion del usuario

Estas en el tema de formulario con campo incremental a peticion del usuario en el foro de PHP en Foros del Web. buenos dias, tengo creado un formulario con dos funciones, INSERT + UPDATE. La idea principal es mostrar el formulario con los datos si existen o ...
  #1 (permalink)  
Antiguo 05/11/2011, 06:34
Avatar de crissrocca  
Fecha de Ingreso: febrero-2011
Mensajes: 51
Antigüedad: 13 años, 9 meses
Puntos: 1
Pregunta formulario con campo incremental a peticion del usuario

buenos dias, tengo creado un formulario con dos funciones, INSERT + UPDATE. La idea principal es mostrar el formulario con los datos si existen o mostrar el formulario con las datos en blanco si no existen.
El usuario puede rellenar el formulario y realizar un INSERT o en el caso contrario cambiar los datos que se muestran y realizar asi un UPDATE.

En un primer momento todo funciona correctamente, pero ahora necesito tener la posibilidad de aumentar los datos del formulario, si por ejemplo el usuario necesita añadir un segundo bloque de estudios o idiomas. Que tenga la opcion de insertar "+Añadir mas Estudios" o "+ Añadir mas Idiomas" y que a su vez las funciones tambien hagan esa funcion.

De una forma clara, el usuario inserta los datos en Idiomas(por ejemplo). Luego quiere añadir un "Segundo Idioma", pulsa en "+ Añadir mas Idiomas" y automaticamente se muestra el mismo campo que antes con los datos vacios para que añada un segundo idioma. Si por un casual el usuario ya tiene un segundo idioma, el que se añadiria seria un tercero, no un segundo... y claro esta, los dos anteriores le darian la posibilidad de ser cambiados y llamar asi a la funcion UPDATE.

Necesito saber como puedo hacer que los campos sean incrementales y como puedo hacer que las funciones para hacer el INSERT o UPDATE en MySql sean lo mas correctamente posible. No quiero incluir 10 querys para una cosa que seguro se puede hacer de forma recursiva.

Si la opcion de añadir nuevos campos se pudiera hacer mediante jQuery seria perfecto.

Os muestro el codigo para el que me pueda echar una mano. Gracias!
  #2 (permalink)  
Antiguo 05/11/2011, 06:47
Avatar de crissrocca  
Fecha de Ingreso: febrero-2011
Mensajes: 51
Antigüedad: 13 años, 9 meses
Puntos: 1
Información Respuesta: formulario con campo incremental a peticion del usuario

formulario.php(1 parte)
[PHP]
<?php
//echo $user_id;
// datos del usuario FROM users
$result = mysql_query("SELECT * FROM users WHERE id = '$user_id'");

// datos del CV FROM CviCvitae - `user_id``computer_capabilities``organization_capa bilities``fax``social_capabilities``other_capabili ties``cvi_cvitaeable_type`
//`technical_capabilities``other_info``artistic_capa bilities``rating`
$queryCviCvitae = mysql_query("SELECT * FROM CviCvitae WHERE user_id = '$user_id'");

// datos Estudios FROM CviEducation - `education_title``center_name``education_capacitie s``education_starts_at``education_ends_at``center_ type`
$queryCviEducation = mysql_query("SELECT * FROM CviEducation WHERE user_id = '$user_id'");

// datos Experiencia FROM CviExperience - `company_sector``company_address``starts_at``funct ions``position``ends_at``company_name`
$queryCviExperience = mysql_query("SELECT * FROM CviExperience WHERE user_id = '$user_id'");

// datos Formacion FROM CviCourse - CviCourse - `course_center``course_hours``course_year``course_ capacities``course_name`
$queryCviCourse = mysql_query("SELECT * FROM CviCourse WHERE user_id = '$user_id'");

// datos Idiomas FROM CviCvitaeLanguage - `language``speaking``reading``talking``writing``li stening`
$queryCviCvitaeLanguage = mysql_query("SELECT * FROM CviCvitaeLanguage WHERE user_id = '$user_id'");

// datos Hobby FROM CviHobby - `hobby_name`
$queryCviHobby = mysql_query("SELECT * FROM CviHobby WHERE user_id = '$user_id'");

$row_CviCvitae = mysql_fetch_array($queryCviCvitae);
$row_CviEducation = mysql_fetch_array($queryCviEducation);
$row_CviExperience = mysql_fetch_array($queryCviExperience);
$row_CviCourse = mysql_fetch_array($queryCviCourse);
$row_CviCvitaeLanguage = mysql_fetch_array($queryCviCvitaeLanguage);
$row_CviHobby = mysql_fetch_array($queryCviHobby);


if ($row = mysql_fetch_array($result)){
echo "<div id='profile_name' ><img style='float: left; padding-right: 15px; padding-top: 2px;' src='wp-content/themes/bowtie/images/icons/black/ID.png' />".$row["first_name"]." ".$row["last_name"]."</div>\n";
} else {
echo "La base de datos esta vacia !";
}


//insertamos los datos del form [$_POST]
if( count( $_POST ) ){
$computer_capabilities = $_POST["computer_capabilities"];
$organization_capabilities = $_POST["organization_capabilities"];
$social_capabilities = $_POST["social_capabilities"];
$other_capabilities = $_POST["other_capabilities"];
$technical_capabilities = $_POST["technical_capabilities"];
$artistic_capabilities = $_POST["artistic_capabilities"];
$other_info = $_POST["other_info"];
//$cvi_cvitaeable_type = $_POST["cvi_cvitaeable_type"];
$education_title = $_POST["education_title"];
$center_name = $_POST["center_name"];
$education_capacities = $_POST["education_capacities"];
$education_starts_at = $_POST["education_starts_at"];
$education_ends_at = $_POST["education_ends_at"];
$center_type = $_POST["center_type"];
$company_sector = $_POST["company_sector"];
$company_address = $_POST["company_address"];
$functions = $_POST["functions"];
$position = $_POST["position"];
$starts_at = $_POST["starts_at"];
$ends_at = $_POST["ends_at"];
$company_name = $_POST["company_name"];
$course_center = $_POST["course_center"];
$course_hours = $_POST["course_hours"];
$course_year = $_POST["course_year"];
$course_capacities = $_POST["course_capacities"];
$course_name = $_POST["course_name"];
$language = $_POST["language"];
$speaking = $_POST["speaking"];
$reading = $_POST["reading"];
$talking = $_POST["talking"];
$writing = $_POST["writing"];
$listening = $_POST["listening"];
$hobby_name = $_POST["hobby_name"];

$user_id = $_POST["user_id"];

echo CviCvitae($computer_capabilities,$organization_cap abilities, $social_capabilities, $other_capabilities, $technical_capabilities, $artistic_capabilities, $other_info, $user_id);
echo CviEducation($education_title, $center_name, $education_capacities, $education_starts_at, $education_ends_at, $center_type, $user_id);
echo CviExperience($company_sector, $company_address, $starts_at, $functions, $position, $ends_at, $company_name, $user_id);
echo CviCourse($course_center, $course_hours, $course_year, $course_capacities, $course_name, $user_id);
echo CviCvitaeLanguage($language, $speaking, $reading, $talking, $writing, $listening, $user_id);
echo CviHobby($hobby_name, $user_id);

//echo CviCVCreate ($computer_capabilities,$organization_capabilities , $social_capabilities, $other_capabilities, $technical_capabilities, $artistic_capabilities, $other_info, $user_id,$education_title, $center_name, $education_capacities, $education_starts_at, $education_ends_at, $center_type, $user_id,$company_sector, $company_address, $starts_at, $functions, $position, $ends_at, $company_name, $user_id,$course_center, $course_hours, $course_year, $course_capacities, $course_name, $user_id,$hobby_name, $user_id,$language, $speaking, $reading, $talking, $writing, $listening, $user_id);

/*echo "<script type='text/javascript'>";
echo "window.alert('Sus datos han sido guardados correctamente');";
echo "location.href='?vista=profile_cv_edit'";
echo "</script>";*/
}

?>
<div id="profile_cv" style="overflow: auto !important; width: 100% !important; height: auto !important" >

<form action="" method="post">
<table width="auto" border="0" style="background: URL('login/img/input.png'); margin-bottom: 20px;" cellpadding="2" cellspacing="2">
<tr>
<td valign="top">
<fieldset>
<legend>Estos son los datos de su Curriculum Vitae</legend>

<!-- ##################################### datos Estudios ##################################### -->
<table id="tablaUsuarios" width="100%" border="0" cellpadding="2" cellspacing="2" style="padding: 15px">
<tr>
<td colspan="2"><span style="border-bottom: 1px solid #ED6D16;">Estudios</span><br/><br/></td>
</tr>
<tr>
<td nowrap="nowrap"><div align="right">Estudios </div>
</td>
<td><input name="education_title" id="education_title" type="text" size="74" value="<?php echo $row_CviEducation["education_title"]; ?>" /></td>
<script type="text/javascript">
var education_title = new LiveValidation('education_title');
education_title.add(Validate.Length, { minimum: 4 } );
education_title.add( Validate.Presence );
</script>
</tr>
<tr>
<td nowrap="nowrap"><div align="right">Titulacion </div></td>
<td><input name="education_capacities" id="education_capacities" type="text" size="74" value="<?php echo $row_CviEducation["education_capacities"]; ?>" /></td>
<script type="text/javascript">
var education_capacities = new LiveValidation('education_capacities');
education_capacities.add(Validate.Length, { minimum: 4 } );
education_capacities.add( Validate.Presence );
</script>
</tr>
<tr>
<td nowrap="nowrap"><div align="right">Centro </div></td>
<td><input name="center_name" id="center_name" type="text" size="74" value="<?php echo $row_CviEducation["center_name"]; ?>" /></td>
<script type="text/javascript">
var title = new LiveValidation('center_name');
center_name.add(Validate.Length, { minimum: 4 } );
center_name.add( Validate.Presence );
</script>
</tr>
<tr>
<td nowrap="nowrap"><div align="right">Tipo de Centro</div></td>
<td><input name="center_type" id="center_type" type="text" size="74" value="<?php echo $row_CviEducation["center_type"]; ?>" /></td>
<script type="text/javascript">
var capacities = new LiveValidation('center_type');
center_type.add(Validate.Length, { minimum: 4 } );
center_type.add( Validate.Presence );
</script>
</tr>
<tr>
<td nowrap="nowrap"><div align="right">Desde el </div></td>
<?php

$starts_at = $row_CviEducation["education_starts_at"];
$starts = array_reverse(explode('-', $starts_at));
$starts_array = array_reverse($starts);
?>
<td><input name="education_starts_at" id="education_starts_at" type="text" size="10" value="<?php print $starts_array[2].'-'.$starts_array[1].'-'.$starts_array[0]; ?>" /></td>
<script type="text/javascript">
var education_starts_at = new LiveValidation('education_starts_at');
education_starts_at.add( Validate.Presence );
education_starts_at.add( Validate.Length, { minimum: 10, maximum: 10 } );
</script>
</tr>
<tr>
<td nowrap="nowrap"><div align="right">hasta el </div></td>
<?php

$ends_at = $row_CviEducation["education_ends_at"];
$ends = array_reverse(explode('-', $ends_at));
$ends_array = array_reverse($ends);
?>
<td><input name="education_ends_at" id="education_ends_at" type="text" size="10" value="<?php print $ends_array[2].'-'.$ends_array[1].'-'.$ends_array[0]; ?>" /></td>
<script type="text/javascript">
var education_ends_at = new LiveValidation('education_ends_at');
education_ends_at.add( Validate.Presence );
education_ends_at.add( Validate.Length, { minimum: 10, maximum: 10 } );
</script>
</tr>
<tr>
<td colspan="2"><input style="float: right; margin-right: 50px;" type="button" onClick="agregarUsuario()" value="A&ntilde;adir" /></td>
</tr>

<!-- ##################################### datos Formacion ##################################### -->
[PHP]
  #3 (permalink)  
Antiguo 05/11/2011, 06:50
Avatar de crissrocca  
Fecha de Ingreso: febrero-2011
Mensajes: 51
Antigüedad: 13 años, 9 meses
Puntos: 1
Respuesta: formulario con campo incremental a peticion del usuario

formulario.php(2 parte)
Código PHP:
Ver original
  1. <!-- ##################################### datos Idiomas ##################################### -->
  2.  
  3.         <tr>
  4.           <td colspan="2"><span style="border-bottom: 1px solid #ED6D16;"><br/>Idiomas<br/></span><br/></td>   
  5.         </tr>
  6.         <tr>
  7.           <td nowrap="nowrap"><div align="right">Idioma </div></td>
  8.           <td><input name="language" id="language" type="text" size="34" value="<?php echo $row_CviCvitaeLanguage["language"]; ?>" /></td>
  9.           <script type="text/javascript">
  10.                 var title = new LiveValidation('language');
  11.                 language.add(Validate.Length, { minimum: 4 } );
  12.                 language.add( Validate.Presence );
  13.             </script>
  14.         </tr>
  15.         <tr><td colspan="2">
  16.                 <select name="speaking" style="display:none">
  17.                     <option value="" selected="selected" ></option>
  18.                 </select>
  19. Hablar
  20.                 <select name="speaking">
  21.                     <option value="<?php echo $row_CviCvitaeLanguage["speaking"]; ?>" selected="selected" ><?php echo $row_CviCvitaeLanguage["speaking"]; ?></option>
  22.                     <option value="1">1</option>
  23.                     <option value="2">2</option>
  24.                     <option value="3">3</option>
  25.                     <option value="4">4</option>
  26.                     <option value="5">5</option>
  27.                     <option value="6">6</option>
  28.                     <option value="7">7</option>
  29.                     <option value="8">8</option>
  30.                     <option value="9">9</option>
  31.                     <option value="10">10</option>
  32.                 </select>
  33.             </td>
  34.           </tr>
  35.        
  36. <!-- ##################################### datos Experiencia Laboral ##################################### -->
  37.         <tr>
  38.           <td colspan="2"><span style="border-bottom: 1px solid #ED6D16;"><br/>Experiencia Laboral<br/></span><br/></td>   
  39.         </tr>
  40.         <tr>        
  41.           <td nowrap="nowrap"><div align="right">Nombre de la Empresa </div></td>
  42.           <td><input name="company_name" id="company_name" type="text" size="74" value="<?php echo $row_CviExperience["company_name"]; ?>" /></td>
  43.           <script type="text/javascript">
  44.                 var title = new LiveValidation('company_name');
  45.                 company_name.add(Validate.Length, { minimum: 4 } );
  46.                 company_name.add( Validate.Presence );
  47.             </script>
  48.         </tr>
  49.         <tr>
  50.           <td nowrap="nowrap"><div align="right">Direccion de la Empresa </div></td>
  51.           <td><input name="company_address" id="company_address" type="text" size="74" value="<?php echo $row_CviExperience["company_address"]; ?>" /></td>
  52.           <script type="text/javascript">
  53.                 var title = new LiveValidation('company_address');
  54.                 company_address.add(Validate.Length, { minimum: 4 } );
  55.                 company_address.add( Validate.Presence );
  56.             </script>
  57.         </tr>
  58.         <tr>
  59.           <td nowrap="nowrap"><div align="right">Sector de la Empresa </div></td>
  60.           <td><input name="company_sector" id="company_sector" type="text" size="74" value="<?php echo $row_CviExperience["company_sector"]; ?>" /></td>
  61.           <script type="text/javascript">
  62.                 var title = new LiveValidation('company_sector');
  63.                 company_sector.add(Validate.Length, { minimum: 4 } );
  64.                 company_sector.add( Validate.Presence );
  65.             </script>
  66.         </tr>
  67.         <tr>        
  68.           <td nowrap="nowrap"><div align="right">Funciones </div></td>
  69.           <td><input name="functions" id="functions" type="text" size="34" value="<?php echo $row_CviExperience["functions"]; ?>" /></td>
  70.           <script type="text/javascript">
  71.                 var title = new LiveValidation('functions');
  72.                 functions.add(Validate.Length, { minimum: 4 } );
  73.                 functions.add( Validate.Presence );
  74.             </script>
  75.         </tr>
  76.         <tr>        
  77.           <td nowrap="nowrap"><div align="right">Categoria </div></td>
  78.           <td><input name="position" id="position" type="text" size="34" value="<?php echo $row_CviExperience["position"]; ?>" /></td>
  79.           <script type="text/javascript">
  80.                 var title = new LiveValidation('position');
  81.                 position.add(Validate.Length, { minimum: 4 } );
  82.                 position.add( Validate.Presence );
  83.             </script>
  84.         </tr>
  85.         <tr>
  86.           <td nowrap="nowrap"><div align="right">Desde el  </div></td>
  87.            <?php
  88.  
  89.                 $start_at = $row_CviExperience["starts_at"];
  90.                 $start = array_reverse(explode('-', $start_at));
  91.                 $start_array = array_reverse($start);
  92.             ?>
  93.           <td><input name="starts_at" id="starts_at" type="text" size="10" value="<?php print $start_array[2].'-'.$start_array[1].'-'.$start_array[0]; ?>" /></td>
  94.           <script type="text/javascript">
  95.                 var title = new LiveValidation('starts_at');
  96.                 starts_at.add(Validate.Numericality);
  97.                 starts_at.add(Validate.Length, { minimum: 4 } );
  98.                 starts_at.add( Validate.Presence );
  99.             </script>
  100.         </tr>
  101.         <tr>
  102.           <td nowrap="nowrap"><div align="right">Hasta el </div></td>
  103.            <?php
  104.  
  105.                 $end_at = $row_CviExperience["ends_at"];
  106.                 $end = array_reverse(explode('-', $end_at));
  107.                 $end_array = array_reverse($end);
  108.             ?>
  109.           <td><input name="ends_at" id="ends_at" type="text" size="10" value="<?php print $end_array[2].'-'.$end_array[1].'-'.$end_array[0]; ?>" /></td>
  110.           <script type="text/javascript">
  111.                 var title = new LiveValidation('ends_at');
  112.                 ends_at.add(Validate.Numericality);
  113.                 ends_at.add(Validate.Length, { minimum: 4 } );
  114.                 ends_at.add( Validate.Presence );
  115.             </script>
  116.         </tr>
  117.                    
  118. <!-- ##################################### datos Capacidades y Trabajo ##################################### -->
  119.         <tr>
  120.           <td colspan="2"><span style="border-bottom: 1px solid #ED6D16;"><br/>Capacidades y Trabajo<br/></span><br/></td> 
  121.         </tr>
  122.         <tr>
  123.           <td nowrap="nowrap"><div align="right">Con ordenadores </div></td>
  124.           <td><input name="computer_capabilities" id="computer_capabilities" type="text" size="74" value="<?php echo $row_CviCvitae ["computer_capabilities"]; ?>" /></td>
  125.           <script type="text/javascript">
  126.                 var title = new LiveValidation('computer_capabilities');
  127.                 computer_capabilities.add(Validate.Length, { minimum: 14 } );
  128.                 computer_capabilities.add( Validate.Presence );
  129.             </script>
  130.         </tr>
  131.         <tr>
  132.           <td nowrap="nowrap"><div align="right">Tecnicas </div></td>
  133.           <td><input name="technical_capabilities" id="technical_capabilities" type="text" size="74" value="<?php echo $row_CviCvitae ["technical_capabilities"]; ?>" /></td>
  134.           <script type="text/javascript">
  135.                 var title = new LiveValidation('technical_capabilities');
  136.                 technical_capabilities.add(Validate.Length, { minimum: 14 } );
  137.                 technical_capabilities.add( Validate.Presence );
  138.             </script>
  139.         </tr>
  140.         <tr>
  141.           <td nowrap="nowrap"><div align="right">Artisticas </div></td>
  142.           <td><input name="artistic_capabilities" id="artistic_capabilities" type="text" size="74" value="<?php echo $row_CviCvitae ["artistic_capabilities"]; ?>" /></td>
  143.           <script type="text/javascript">
  144.                 var title = new LiveValidation('artistic_capabilities');
  145.                 artistic_capabilities.add(Validate.Length, { minimum: 14 } );
  146.                 artistic_capabilities.add( Validate.Presence );
  147.             </script>
  148.         </tr>
  149.         <tr>        
  150.           <td nowrap="nowrap"><div align="right">Poder de Organizacion </div></td>
  151.           <td><input name="organization_capabilities" id="organization_capabilities" type="text" size="74" value="<?php echo $row_CviCvitae ["organization_capabilities"]; ?>" /></td>
  152.           <script type="text/javascript">
  153.                 var title = new LiveValidation('organization_capabilities');
  154.                 organization_capabilities.add(Validate.Length, { minimum: 14 } );
  155.                 organization_capabilities.add( Validate.Presence );
  156.             </script>
  157.         </tr>
  158.         <tr>        
  159.           <td nowrap="nowrap"><div align="right">Trabajo en Grupo </div></td>
  160.           <td><input name="social_capabilities" id="social_capabilities" type="text" size="74" value="<?php echo $row_CviCvitae["social_capabilities"]; ?>" /></td>
  161.           <script type="text/javascript">
  162.                 var title = new LiveValidation('social_capabilities');
  163.                 social_capabilities.add(Validate.Length, { minimum: 14 } );
  164.                 social_capabilities.add( Validate.Presence );
  165.             </script>
  166.         </tr>
  167.         <tr>
  168.           <td nowrap="nowrap"><div align="right">Otras Capacidades </div></td>
  169.           <td><input name="other_capabilities" id="other_capabilities" type="text" size="74" value="<?php echo $row_CviCvitae ["other_capabilities"]; ?>" /></td>
  170.           <script type="text/javascript">
  171.                 var title = new LiveValidation('other_capabilities');
  172.                 other_capabilities.add(Validate.Length, { minimum: 14 } );
  173.                 other_capabilities.add( Validate.Presence );
  174.             </script>
  175.         </tr>
  176.         <tr>        
  177.           <td nowrap="nowrap"><div align="right">Otra informacion </div></td>
  178.           <td><input name="other_info" id="other_info" type="text" size="74" value="<?php echo $row_CviCvitae ["other_info"]; ?>" /></td>
  179.           <script type="text/javascript">
  180.                 var title = new LiveValidation('other_info');
  181.                 other_info.add(Validate.Length, { minimum: 14 } );
  182.                 other_info.add( Validate.Presence );
  183.             </script>
  184.           </tr>
  185.         <tr>
  186.           <td>&nbsp;<br/><br/></td>
  187.           <input type="hidden" name="user_id" id ="user_id" value="<? echo $user_id; ?>" />
  188.           <td align="right"><input type="submit" value="enviar" /> </td>
  189.           </tr>
  190.         </table>
  191.     </fieldset></td>
  192.     </tr>
  193. </table>
  194. </form>
  195.  
  196. </div>
  197. [/PHP]
  #4 (permalink)  
Antiguo 05/11/2011, 06:51
Avatar de crissrocca  
Fecha de Ingreso: febrero-2011
Mensajes: 51
Antigüedad: 13 años, 9 meses
Puntos: 1
Respuesta: formulario con campo incremental a peticion del usuario

common.php (este fichero se incluye al formulario para acceder a la bbdd y contiene las funciones de la web)
Código PHP:
Ver original
  1. //insertamos los datos del form [$_POST]
  2. if( count( $_POST ) ){  
  3.     $computer_capabilities  = $_POST["computer_capabilities"];
  4.     $organization_capabilities  = $_POST["organization_capabilities"];
  5.     $social_capabilities  = $_POST["social_capabilities"];
  6.     $other_capabilities  = $_POST["other_capabilities"];
  7.     $technical_capabilities  = $_POST["technical_capabilities"];
  8.     $artistic_capabilities = $_POST["artistic_capabilities"];
  9.     $other_info = $_POST["other_info"];
  10.     //$cvi_cvitaeable_type  = $_POST["cvi_cvitaeable_type"];
  11.     $education_title  = $_POST["education_title"];
  12.     $center_name  = $_POST["center_name"];
  13.     $education_capacities  = $_POST["education_capacities"];
  14.         $education_starts_at  = $_POST["education_starts_at"];
  15.         $education_ends_at  = $_POST["education_ends_at"];
  16.     $center_type  = $_POST["center_type"];
  17.     $company_sector  = $_POST["company_sector"];
  18.     $company_address  = $_POST["company_address"];
  19.     $functions  = $_POST["functions"];
  20.     $position  = $_POST["position"];
  21.         $starts_at  = $_POST["starts_at"];
  22.         $ends_at  = $_POST["ends_at"];
  23.     $company_name  = $_POST["company_name"];
  24.     $course_center  = $_POST["course_center"];
  25.     $course_hours  = $_POST["course_hours"];
  26.     $course_year  = $_POST["course_year"];
  27.     $course_capacities  = $_POST["course_capacities"];
  28.     $course_name  = $_POST["course_name"];
  29.     $language  = $_POST["language"];
  30.     $speaking  = $_POST["speaking"];
  31.     $reading  = $_POST["reading"];
  32.     $talking  = $_POST["talking"];
  33.     $writing  = $_POST["writing"];
  34.     $listening  = $_POST["listening"];
  35.     $hobby_name  = $_POST["hobby_name"];
  36.  
  37.     $user_id = $_POST["user_id"];
  38. }
  39.  
  40. //Aqui incluyo los parametros para hacer la conexion con la BBDD
  41.  
  42. function CviCvitae($computer_capabilities,$organization_capabilities, $social_capabilities, $other_capabilities, $technical_capabilities, $artistic_capabilities, $other_info, $user_id){
  43.         $queryCviCvitae = mysql_query("SELECT * FROM CviCvitae WHERE user_id = '$user_id'");
  44.         $row_CviCvitae = mysql_fetch_array($queryCviCvitae);
  45.         $id_1 = $row_CviCvitae['id'];
  46.        
  47.         //echo $row_CviCvitae['user_id'];
  48.         //printf("Registros actualizados: %d\n", mysql_affected_rows());
  49.        
  50.         if (isset($id_1)){
  51.             $ejecuCviCvitae = "UPDATE CviCvitae SET computer_capabilities = '$computer_capabilities', organization_capabilities = '$organization_capabilities', social_capabilities = '$social_capabilities', other_capabilities = '$other_capabilities', technical_capabilities = '$technical_capabilities', artistic_capabilities = '$artistic_capabilities', other_info = '$other_info' WHERE user_id = '$user_id' AND id = '$id_1'";
  52.             //printf("Registros actualizados: %d\n", mysql_affected_rows());
  53.         } else {
  54.             $ejecuCviCvitae = "INSERT INTO CviCvitae (computer_capabilities, organization_capabilities, social_capabilities, other_capabilities, technical_capabilities, artistic_capabilities, other_info, user_id) VALUES ('$computer_capabilities', '$organization_capabilities', '$social_capabilities', '$other_capabilities', '$technical_capabilities', '$artistic_capabilities', '$other_info', '$user_id')" ;
  55.             //printf("Registros actualizados: %d\n", mysql_affected_rows());
  56.         }
  57.     }
  58.    
  59.     function CviEducation($education_title, $center_name, $education_capacities, $education_starts_at, $education_ends_at, $center_type, $user_id){
  60.         //ordenamos las fechas $education_starts_at - $education_ends_at
  61.         $arr = explode('-', $education_starts_at); $new_education_starts_at = $arr[2].'-'.$arr[1].'-'.$arr[0];
  62.         $brr = explode('-', $education_ends_at); $new_education_ends_at = $brr[2].'-'.$brr[1].'-'.$brr[0];
  63.        
  64.         $queryCviEducation = mysql_query("SELECT * FROM CviEducation WHERE user_id = '$user_id'");
  65.         $row_CviEducation = mysql_fetch_array($queryCviEducation);
  66.        
  67.         $id_2 = $row_CviEducation['id'];
  68.                
  69.         if (isset($id_2)){
  70.             $ejecuCviEducation = "UPDATE CviEducation SET education_title = '$education_title', center_name = '$center_name', education_capacities = '$education_capacities', education_starts_at = '$new_education_starts_at', education_ends_at = '$new_education_ends_at', center_type = '$center_type' WHERE user_id = '$user_id' AND id = '$id_2'";
  71.         } else {
  72.             $ejecuCviEducation = "INSERT INTO CviEducation (education_title, center_name, education_capacities, education_starts_at, education_ends_at, center_type, user_id) VALUES ('$education_title', '$center_name', '$education_capacities', '$new_education_starts_at', '$new_education_ends_at', '$center_type', '$user_id')";
  73.         }
  74.     }  
  75.  
  76.     function CviExperience($company_sector, $company_address, $starts_at, $functions, $position, $ends_at, $company_name, $user_id){
  77.         //ordenamos las fechas $starts_at - $ends_at
  78.         $crr = explode('-', $starts_at); $new_starts_at = $crr[2].'-'.$crr[1].'-'.$crr[0];
  79.         $urr = explode('-', $ends_at); $new_ends_at = $urr[2].'-'.$urr[1].'-'.$urr[0];
  80.        
  81.         $queryCviExperience = mysql_query("SELECT * FROM CviExperience WHERE user_id = '$user_id'");
  82.         $row_CviExperience = mysql_fetch_array($queryCviExperience);
  83.        
  84.         $id_3 = $row_CviExperience['id'];
  85.                
  86.         if (isset($id_3)){
  87.             $ejecuCviExperience = mysql_query("UPDATE CviExperience SET company_sector = '$company_sector', company_address = '$company_address', starts_at = '$new_starts_at', functions = '$functions', position = '$position', ends_at = '$new_ends_at', company_name = '$company_name' WHERE user_id = '$user_id' AND id = '$id_3'");
  88.         } else {
  89.             $ejecuCviExperience = mysql_query("INSERT INTO CviExperience (company_sector, company_address, starts_at, functions, position, ends_at, company_name, user_id) VALUES ('$company_sector', '$company_address', '$new_starts_at', '$functions', '$position', '$new_ends_at', '$company_name', '$user_id')");
  90.         }
  91.     }  
  92.  
  93.  
  94.     function CviCourse($course_center, $course_hours, $course_year, $course_capacities, $course_name, $user_id){
  95.         $queryCviCourse = mysql_query("SELECT * FROM CviCourse WHERE user_id = '$user_id'");
  96.         $row_CviCourse = mysql_fetch_array($queryCviCourse);
  97.        
  98.         $id_4 = $row_CviCourse['id'];
  99.                
  100.         if (isset($id_4)){
  101.             $ejecuCviCourse = mysql_query("UPDATE CviCourse SET course_center = '$course_center', course_hours = '$course_hours', course_year = '$course_year', course_capacities = '$course_capacities', course_name = '$course_name' WHERE user_id = '$user_id' AND id = '$id_4'");
  102.         } else {
  103.             $ejecuCviCourse = mysql_query("INSERT INTO CviCourse (course_center, course_hours, course_year, course_capacities, course_name, user_id) VALUES('$course_center','$course_hours','$course_year','$course_capacities','$course_name', '$user_id')");
  104.         }
  105.     }  
  106.  
  107.  
  108.     function CviCvitaeLanguage($language, $speaking, $reading, $talking, $writing, $listening, $user_id){
  109.         $queryCviCvitaeLanguage = mysql_query("SELECT * FROM CviCvitaeLanguage WHERE user_id = '$user_id'");
  110.         $row_CviCvitaeLanguage = mysql_fetch_array($queryCviCvitaeLanguage);
  111.        
  112.         $id_5 = $row_CviCvitaeLanguage['id'];
  113.                
  114.         if (isset($id_5)){
  115.             $ejecuCviCvitaeLanguage = mysql_query("UPDATE CviCvitaeLanguage SET language = '$language', speaking = '$speaking', reading = '$reading', talking= '$talking', writing = '$writing', listening = '$listening' WHERE user_id = '$user_id' AND id = '$id_5'");
  116.         } else {
  117.             $ejecuCviCvitaeLanguage = mysql_query("INSERT INTO CviCvitaeLanguage (language, speaking, reading, talking, writing, listening, user_id) VALUES ('$language', '$speaking', '$reading', '$talking', '$writing', '$listening', '$user_id')");
  118.         }
  119.     }  
  120.  
  121.  
  122.     function CviHobby($hobby_name, $user_id){
  123.         $queryCviHobby = mysql_query("SELECT * FROM CviHobby WHERE user_id = '$user_id'");
  124.         $row_CviHobby = mysql_fetch_array($queryCviHobby);
  125.        
  126.         $id_6 = $row_CviHobby['id'];
  127.                
  128.         if (isset($id_6)){
  129.                 $ejecuCviHobby = mysql_query("UPDATE CviHobby SET hobby_name = '$hobby_name' WHERE user_id = '$user_id' AND id = '$id_6'");
  130.         } else {
  131.                 $ejecuCviHobby = mysql_query("INSERT INTO CviHobby ( hobby_name, user_id) VALUES ('$hobby_name', '$user_id')");
  132.         }
  133.     }

Gracias a los que puedan ayudar en algo!

Etiquetas: mysql, recursivo, formulario, campos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:37.