i am trying to export the results from a form into the script of another php in form of variables :

ex.

form proccess script (globalvar.php)

$dbtype = $_POST;
$dbhost = $_POST;
$dbname = $_POST;
$dbpass = $_POST;
$dbport = $_POST;
$dbtable = $_POST;

new php (varheader.php)

$dbtype = 'mysql' ;
$dbhost = 'localhost' ;
$dbname = 'rootusername' ;
$dbpass = 'rootpassword' ;
$dbport = '10985' ;
$dbtable = 'script' ;

i wrote this script to accomplish that and to completely write the php script:

//set up vars for file open scripts
    $fpvars = fopen("varheader.php", 'w');

    //set up vars for output scripts

   //database
    $dboutput = "//database vars \n"."dbtype = '".$dbtype."'; \n". "dbhost = '".$dbhost."'; \n"."dbtype = '".$dbtype."'; \n"."dbname = '".$dbname."'; \n"."dbport = '".$dbport."'; \n"."\n". "database = array($dbtype, $dbhost, $dbname, $dbpass, $dbport);";

    //phptags
    $starttag = "<?php";
    $blankline = "\n";
    $closetag = "\n"."?>";

fopen("varheader.php", 'w');
fwrite($fpvars, $starttag, strlen($starttag));
fwrite($fpvars, $blankline, strlen($blankline));
fwrite($fpvars, $dboutput, strlen($dboutput));
fwrite($fpvars, $blankline, strlen($blankline));
fwrite($fpvars, $closetag, strlen($closetag));

it succsessfully writes the document but does this:

<?php

//database vars
   mysql = 'mysql' ; 
     localhost = 'localhost' ;
     rootusername = 'rootusername' ;
     rootpassword = 'rootpassword' ;
     10985 = '10985' ;
     script = 'script' ;

?>

can anyone help?

what are you actually asking? I think that you are saying that you are missing the $ at the start of the variables is that correct?

yes

im looking for:
$dbtype = 'mysql' ;
$dbhost = 'localhost' ;
$dbname = 'rootusername' ;
$dbpass = 'rootpassword' ;
$dbport = '10985' ;
$dbtable = 'script' ;

but get:
mysql = 'mysql' ;
localhost = 'localhost' ;
rootusername = 'rootusername' ;
rootpassword = 'rootpassword' ;
10985 = '10985' ;
script = 'script' ;

I have just run the script that you have posted and I first results that I got was

<?php
//database vars 
dbtype = 'a'; 
dbhost = 'b'; 
dbtype = 'a'; 
dbname = 'b'; 
dbport = 'b'; 

database = array(a, b, b, b, b);

?>

then by adding

\$

in front of all of the varible names in $dboutput I get

<?php
//database vars 
$dbtype = 'a'; 
$dbhost = 'b'; 
$dbtype = 'a'; 
$dbname = 'b'; 
$dbport = 'b'; 

database = array(a, b, b, b, b);

?>

not sure where you are getting the variable names of mysql,localhost,etc from.

(sorry about the a and b as values I was feeling lazy)

Just in case you were wondering this your modified dboutput string

$dboutput = "//database vars \n"."\$dbtype = '".$dbtype."'; \n". "\$dbhost = '".$dbhost."'; \n"."\$dbtype = '".$dbtype."'; \n"."\$dbname = '".$dbname."'; \n"."\$dbport = '".$dbport."'; \n"."\n". "database = array($dbtype, $dbhost, $dbname, $dbpass, $dbport);";

thanks! that did it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.