title: php variables from another php file
body: <p>A lot of versions around but i can not get it right...</p>
  
  <p>I need to transfer variables from one php script file to another.</p>
  
  <p><code>script1.php</code> has the variables:</p>
  
  <pre><code>$t1 =  $_POST['t1'];
  $t2 =  $_POST['t2'];
  </code></pre>
  
  <p>and I need to work with these variables in another script file - <code>script2.php</code></p>
  
  <p>How can I access these variables in <code>script2.php</code> file?</p>
  
  <p>OK. i will post all the script.</p>
  
  <p>script1.php or in fact getImage.php is following</p>
  
  <pre><code>&lt;?php 
  $today = date("Ymd_His"); 
  
  $t1 =  $_POST['t1']; //mazais nosaukums
  $t2 =  $_POST['t2']; //lielais nosaukums
  
  $c1 =  $_POST['c1'];  //kjeksis
  $c2 =  $_POST['c2'];  //kjeksis 
  $c3 =  $_POST['c3'];  //kjeksis 
  $c4 =  $_POST['c4'];  //kjeksis 
  
  $mazais =  $_POST['mazais'];    //maza bilde atseviskji
  $lielais =  $_POST['lielais'];    //maza bilde atseviskji    
  
  $response = "";
  
  $error_response = "error.php";
  $succes_response = "nextstep.php";
  
  
  $etikjete = base64_decode($_REQUEST['png']);
  if ($handle1 = fopen("render/".$today.'.png', 'w+')) {
      if (!fwrite($handle1, $etikjete) === FALSE) {
          fclose($handle1);
          $response .= "Success etikjete! "; 
      } else {
          $response .=  "fwrite error etikjete! ";
          $error = true;
      }
  } else {
      $response .=  "fopen error etikjete! ";
      $error = true;    
  }
  
  if($mazais){
      $etikjete = base64_decode($mazais);
      if ($handle1 = fopen("render/".$today.'_mazais.png', 'w+')) {
          if (!fwrite($handle1, $etikjete) === FALSE) {
              fclose($handle1);
              $response .= "Success mazais! "; 
          } else {
              $response .=  "fwrite error mazais! ";
              $error = true;
          }
      } else {
          $response .=  "fopen error mazais! ";
          $error = true;    
      } 
  }      
  if($lielais){
      $etikjete = base64_decode($lielais);
      if ($handle1 = fopen("render/".$today.'_lielais.png', 'w+')) {
          if (!fwrite($handle1, $etikjete) === FALSE) {
              fclose($handle1);
              $response .= "Success lielais! "; 
          } else {
              $response .=  "fwrite error lielais! ";
              $error = true;
          }
      } else {
          $response .=  "fopen error lielais! ";
          $error = true;    
      } 
  }
  if($error){
           echo $error_response;
  } else {
          echo $succes_response;
  }
  ?&gt;
  </code></pre>
  
  <p>and script2.php here is called nextstep.php
  and in this nextstep.php I need to save the variables from getImage.php into database. nextstep.php so far is like this but does not work. connection with db is ok, if I set different independent variables on nextstep.php then they gets stored into db.</p>
  
  <pre><code>&lt;?php 
  
  include 'getImage.php';
  
  // Connects to your Database
  mysql_connect("localhost", "user", "pass") or die(mysql_error()) ;
  mysql_select_db("myDB") or die(mysql_error()) ;
  
  //Writes the information to the database
  mysql_query("INSERT INTO jos_orders (maza_bilde,liela_bilde,mazais_nosaukums,lielais_nosaukums)
  VALUES ('$t1', '$c2', '$mazais', '$lielais')") ;
  
  ?&gt;
  </code></pre>