Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/11/2011, 06:51
Avatar de crissrocca
crissrocca
 
Fecha de Ingreso: febrero-2011
Mensajes: 51
Antigüedad: 13 años, 8 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!