Click to See Complete Forum and Search --> : write php to generated file


marcusami
05-05-2008, 02:02 PM
I am trying to create a file on the fly with php from user input that is then put in a database, but i also want to write php to this new page.

it is using a database so i am trying to write a $product_ID var
to the page that holds product id, so it can then look up the product and product info on the generated page from the database

kind of along the lines of


$stringData = "<?php include 'connect.php'; $product_ID = ".$result_id."; $result = mysql_query('SELECT t_Loc, t_Loc_a, t_Loc_b, t_File FROM papas.trailers WHERE id = '$product_ID' ') or die(mysql_error());";

fwrite($aFileHandler, $stringData);


but i am failing to be able to do this

i really need some help
thanks
Marcus

jamesm6162
05-05-2008, 02:34 PM
Escape all the dollar signs in your string. php interprets dollar signs in double quoted strings as actual variable names.
Like this:

$stringData = "<?php include 'connect.php'; \$product_ID = ".$result_id."; \$result = mysql_query('SELECT t_Loc, t_Loc_a, t_Loc_b, t_File FROM papas.trailers WHERE id = '\$product_ID' ') or die(mysql_error());";

jamesm6162
05-05-2008, 02:36 PM
Escape all the dollar signs in your string. php interprets dollar signs in double quoted strings as actual variable names.
Like this:

$stringData = "<?php include 'connect.php'; \$product_ID = ".$result_id."; \$result = mysql_query('SELECT t_Loc, t_Loc_a, t_Loc_b, t_File FROM papas.trailers WHERE id = '\$product_ID' ') or die(mysql_error());";

marcusami
05-05-2008, 02:50 PM
thanks, still having trouble though
its writing a blank page


$aFileName = "trailers/".$now."_trailer_b.php";

$aFileHandle = fopen($aFileName, 'w') or die("can't open file");

$result_id = mysql_query("SELECT id FROM papas.trailers WHERE t_File = '$aFileName' ") or die(mysql_error());

$stringData = "<?php include 'connect.php'; \$product_ID = ".$result_id."; \$result = mysql_query('SELECT t_Loc, t_Loc_a, t_Loc_b, t_File FROM papas.trailers WHERE id = '\$product_ID' ') or die(mysql_error());";

fwrite($aFileHandle, $stringData);
fclose($aFileHandle);


anyideas?

regards
Marcus

marcusami
05-05-2008, 03:04 PM
solved!

didnt end data string with ?> ha

thanks

regards
Marcus

jamesm6162
05-06-2008, 12:55 PM
Welcome

Cheers