Jump to content

PHP code wont write to file


JC5

Recommended Posts

I have this code

<?php/** * BBoardX 1.0 BETA * Copyright © 2008 BBoardX, All Rights Reserved * * Website: http://www.bboardx.com * License: http://www.bboardx.com/license * */$myFile = "connect.php";$fh = fopen($myFile, 'w') or die("can't open file");$stringData = "<?php\n$db = mysql_connect({$_POST['req_db_host']},{$_POST['username']},{$_POST['password']}) or die('Could not connect');\n$admin_email={$_POST['admin_email']};\n$admin_password={$_POST['admin_password']};\nif(!$db)\n die('no db');\nif(!mysql_select_db({$_POST['database']},$db))\n die('No database selected.');\nif(get_magic_quotes_gpc())\n{\n$_GET = array_map('stripslashes', $_GET);\n$_POST = array_map('stripslashes', $_POST);\n$_COOKIE=array_map('stripslashes', $_COOKIE);\n}\n$_GET = array_map('mysql_real_escape_string', $_GET);\n$_POST = array_map('mysql_real_escape_string', $_POST);\n$_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);\n?>";fwrite($fh, $stringData);fclose($fh);Header ('Location runsql.php');?>

and not one forum has been able to answer me why the code does not write to the connect.php file. Cmon guys be the first to answer why it wont work

Link to comment
Share on other sites

Do you know the answer? Are you just asking to see if we get it? (Just checking; I don't like pop quizzes.)What permissions does connect.php have?Add this to the top of the script and report any extra output:

ini_set('display_errors', 'On');error_reporting(E_ALL | E_STRICT);

After testing with the above extra two lines, change the fwrite line to this and report any extra output:

fwrite($fh, $stringData) or die('The file could not be written.');

Link to comment
Share on other sites

Even if you figure out why your file isn't writing, you're not going to like the results. You're building your $stringData variable inside double quotes. That means expressions like $db are going to be interpolated, not copied. Or, in other words, where you expect to find $db in the file, you will find the interpolated value of $db, which is null, so you'll find nothing there. And that will be true of all expressions like that.Try putting an escape character before the $ for those expressions. I.E., instead of writing $db write \$db. The variables that SHOULD be interpolated, leave those alone.You also don't need all those newline characters. In PHP, when a quoted expression includes multiple lines, the newline characters are understood. This is not the case in, say, Perl.

Link to comment
Share on other sites

Ha no this is not a quiz, this is an actual problem I haveI took your suggetsionsand now have this code, yet to be tested

<?php/** * BBoardX 1.0 BETA * Copyright © 2008 BBoardX, All Rights Reserved * * Website: http://www.bboardx.com * License: http://www.bboardx.com/license * */$myFile = "connect.php";$fh = fopen($myFile, 'w') or die("can't open file");$stringData = "<?php\n\$db = mysql_connect({\$_POST['req_db_host']},{\$_POST['username']},{\$_POST['password']}) or die('Could not connect');$admin_email={\$_POST['admin_email']};$admin_password={\$_POST['admin_password']};if(!$db) die('no db');if(!mysql_select_db({\$_POST['database']},\$db)) die('No database selected.');if(get_magic_quotes_gpc()){$_GET = array_map('stripslashes', \$_GET);$_POST = array_map('stripslashes', \$_POST);$_COOKIE=array_map('stripslashes', \$_COOKIE);}\$_GET = array_map('mysql_real_escape_string', \$_GET);\$_POST = array_map('mysql_real_escape_string', \$_POST);\$_COOKIE = array_map('mysql_real_escape_string', \$_COOKIE);?>";fwrite($fh, $stringData);fclose($fh);Header ('Location: runsql.php');?>

Link to comment
Share on other sites

I never said adding the slash would make it work. Of course something else, like permissions, is getting in the way first.
I have the file permissions at 0755. should they be different?
Link to comment
Share on other sites

HAAHAHAHAHHAHAHAH EZEZEZEZEZEZ FIGURED ITTTTTi had <form action="runsql.php" method="post>and in that file it didnt redirect to install.php where the fwrite function was in so it never got referencedand it works nowEZEZEZEEZEZEZEZEZ[/happyness]yay

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...