Advertisement
Guest User

Untitled

a guest
Sep 7th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2.    
  3. $con = mysqli_connect( "localhost","root","","teste" ); // ◄■ CONNECT TO DATABASE.
  4.    
  5.  
  6.         //$id_resp = (isset($_POST['id_resp']) ? $_POST['id_resp'] : '');
  7.         //$id = $_SESSION['UtilizadorID'];
  8.    
  9.         //$data = (isset($_POST['data']) ? $_POST['data'] : '');
  10.            
  11.     $file = fopen("teste.csv","a"); //filename
  12.  
  13. I change the POST variable to array variable with following output:
  14.  
  15. array(8) { ["corp_resp&77&2&2017-09-07&80&76"]=> string(4) "0.00" ["corp_resp&78&2&2017-09-07&80&76"]=> string(4) "0.00" ["corp_resp&79&2&2017-09-07&80&76"]=> string(4) "0.00" ["corp_resp&80&2&2017-09-07&80&76"]=> string(4) "0.00" ["corp_resp&81&2&2017-09-07&80&76"]=> string(4) "0.30" ["corp_resp&82&2&2017-09-07&80&76"]=> string(4) "0.00" ["corp_resp&83&2&2017-09-07&80&76"]=> string(4) "0.00" ["corp_resp&84&2&2017-09-07&80&76"]=> string(4) "0.70" } array(1) { [0]=> string(4) "0.70" }
  16.  
  17.  
  18.  if ( isset($_POST) ) {
  19.    
  20.    foreach ( $_POST as $key  )
  21.       $cr = explode( "&",$key );
  22.         //mysqli_query( $con,"insert into tem (menuid,corp_resp_template,id,data,id_tem,menuIdPai) " .
  23.           //                              "values ('{$cr[1]}','$value', '{$cr[2]}', '{$cr[3]}', '{$cr[4]}', '{$cr[5]}')" );
  24.  
  25. I am introducing for database but i want to introduce to csv.
  26.  
  27. I try in that way to csv file. But is empty $csv only with ;
  28.  
  29.     var_dump($cr);
  30.          $csv = $cr[1].";".$value.";".$cr[3].";".$cr[4].";".$cr[5];      
  31.  
  32.              var_dump($csv);
  33.                  
  34.                    //fputcsv($file,explode(';',$csv), ";");
  35.            
  36.  
  37. fclose($file);    
  38.  }
  39.   else {
  40.        
  41.      echo "task option is required";
  42.      exit;
  43.    }
  44.  
  45.  
  46.    
  47.        
  48.         echo "<center>AdicIonada com sucesso.</center>";
  49.         echo '<br>';
  50.         echo '<br>';
  51.    
  52.  
  53.  
  54.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement