monkeypaw201 Posted July 18, 2008 Share Posted July 18, 2008 i am trying to write to a file... BUT im trying to write PHP code to a file and it doesnt work... <?php $ourFileName = "data.php"; $ourFileHandle = fopen($ourFileName, 'w') or die("<font color='red'>Error creating file</font>"); fclose($ourFileHandle); $myFile = "data.php"; $fh = fopen($myFile, 'w') or die("<font color='red'>Error Writing to file</font>"); $stringData = "<?php \n\n$SETTINGS = Array (\n\n"; fwrite($fh, $stringData); $stringData = "$hostname_conn_abrv"; fwrite($fh, $stringData); $stringData = " = " . $_POST['server'] . "; //database hostname, usually always localhost\n"; fwrite($fh, $stringData); $stringData = "$database_conn_abrv"; fwrite($fh, $stringData); $stringData = " = " . $_POST['database'] . "; //database name\n"; fwrite($fh, $stringData); $stringData = "$username_conn_abrv"; fwrite($fh, $stringData); $stringData = " = " . $_POST['user'] . "; // database username\n"; fwrite($fh, $stringData); $stringData = "$password_conn_abrv"; fwrite($fh, $stringData); $stringData = " = " . $_POST['pass'] . "; // database \n"; fwrite($fh, $stringData); $stringData = "\n$conn_abrv = mysql_pconnect($hostname_conn_abrv, $username_conn_abrv, $password_conn_abrv) or trigger_error(mysql_error(),E_USER_ERROR); \n\n ); \n?>"; fwrite($fh, $stringData); fclose($fh); ?> thanks Quote Link to comment https://forums.phpfreaks.com/topic/115478-solved-writing-to-a-file/ Share on other sites More sharing options...
craygo Posted July 18, 2008 Share Posted July 18, 2008 if you want to write php code then use single quotes not double quotes. Single quotes will write things just as they are. Quote Link to comment https://forums.phpfreaks.com/topic/115478-solved-writing-to-a-file/#findComment-593653 Share on other sites More sharing options...
Third_Degree Posted July 18, 2008 Share Posted July 18, 2008 Or concatenate your variables. Either way... Quote Link to comment https://forums.phpfreaks.com/topic/115478-solved-writing-to-a-file/#findComment-593655 Share on other sites More sharing options...
monkeypaw201 Posted July 18, 2008 Author Share Posted July 18, 2008 Its always a simple solution isn't it Either a missing colon or wrong quotes Quote Link to comment https://forums.phpfreaks.com/topic/115478-solved-writing-to-a-file/#findComment-593658 Share on other sites More sharing options...
monkeypaw201 Posted July 18, 2008 Author Share Posted July 18, 2008 ahhh, but chaos strikes once again.... Remember where it had the \n for a new line? yea.. with single quotes it doesnt make line breaks Quote Link to comment https://forums.phpfreaks.com/topic/115478-solved-writing-to-a-file/#findComment-593661 Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 Then you have to do something like this: <?php fwrite($fp,'This is a test ... test .... test... test'."\n"); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/115478-solved-writing-to-a-file/#findComment-593663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.