insert into multi table with specific field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nel
    New Member
    • Aug 2006
    • 4

    insert into multi table with specific field

    anybody of u can help me?
    i want some code to insert array coding in database mysql..where this process to many table and to specified field...
    this table name and field name i taken from database from select statement....
    thanks....
  • hemashiki
    New Member
    • Aug 2006
    • 34

    #2
    can u send your code(upto which you have done) becoz without coding it is diffiicult for me to understand

    Comment

    • nel
      New Member
      • Aug 2006
      • 4

      #3
      Originally posted by hemashiki
      can u send your code(upto which you have done) becoz without coding it is diffiicult for me to understand
      this is my code:
      i hope u can understand:

      <?php

      $mysql_link = mysql_connect(" localhost", "root", "");

      // select the 'store' database
      mysql_select_db ("mydb", $mysql_link);


      $petak=$_REQUES T["petak_no"];
      for($a=0;$a<$pe tak;$a++){

      $table_name[$a]=$_REQUEST["table_name "][$a];
      $value[$a]=$_REQUEST["petak"][$a];

      $features[$a]=$_REQUEST["features"][$a];


      echo $table_name[$a];
      echo $value[$a];
      echo $features[$a];

      //$query = "INSERT INTO <table>(
      $query[$a] = "INSERT INTO ".$table_na me[$a]." (";


      //$query = "INSERT INTO <table>($fldnm1 , $fldnm2, ... $fldnmN
      //$fldnmN = $fieldnameN //EXPLANATION//
      $trigger = 0;
      foreach($_POST as $features[$a]=> $value[$a]){
      if($trigger > 0) $query[$a] = $query[$a] . ", ";
      $query[$a] = $query[$a] . $features[$a];
      $trigger++;
      }


      //$query = "INSERT INTO <table>(fldnm 1, fldnm2, ... fldnmN) VALUES(trim('
      $query[$a] = $query[$a] . ") VALUES (('";


      //$query = "INSERT INTO <table>(fldnm 1, fldnm2, ... fldnmN) VALUES(trim('va lue1'), trim('value2'), trim('valueN')
      $trigger = 0;
      foreach($_POST as $features[$a] => $value[$a]){
      if($trigger > 0) $query[$a] = $query[$a] . ", ('";
      $query[$a] = $query[$a] . $value[$a]."')";
      $trigger++;
      }


      //$query = "INSERT INTO <table>(fldnm 1, fldnm2, ... fldnmN) VALUES(trim('va lue1'), trim('value2'), trim('valueN')) ;
      $query[$a] = $query[$a] . ");";


      //IF query runs, return. Else, tell me why
      //echo $query."<br><br >";
      if($result[$a] = mysql_query($qu ery[$a])) {return(0); echo "Success";}
      else echo(mysql_erro r());
      }



      ?>

      Comment

      Working...