Hello!
I have the following code below. When I run the setup.php that contaisn this code, it writes to a file. But, the output written to the file is in one long line. I need it to put breaks in between each line. What do I need to add to the following code to get it to output the information right?
Here is the code that writes to the file:
write_config($_POST['host'],$_POST['user'],$_POST['password'],$_POST['table'],$_POST['perpage'],$_POST['description'],$_POST['admin_user'],$_POST['admin_password']);
}
function write_config($host,$user,$password,$table,$pages,$des,$admin_user,$admin_password){
$fp = fopen('port.config.php', "w");
if(!$fp){
setup_index('Unable to open port.config.php Try Chmoding it 777');
}
$f .= '<?';
$f .= '## Pages Per Page';
$f .= '$' . 'perpage = '.$pages.';';
$f .= '$' . 'description_length = '.$des.';' ;
$f .= '## MySQL';
$f .= '$' . 'server = "'.$host.'";' ;
$f .= '$' . 'user = "'.$user.'";' ;
$f .= '$' . 'password = "'.$password.'";';
$f .= '$' . 'database = "'.$table.'";';
$f .= '$' . 'admin_user = "'.$admin_user.'";';
$f .= '$' . 'admin_password = "'.$admin_password.'";' ;
$f .= '?>';
fwrite($fp, $f);
fclose($fp);
}
========================
This is how the ouput file looks:
<?## Pages Per Page$perpage = 10;$description_length = 150;## MySQL$server = "localhost";$user = "shaxs";$password = "password";$database = "db_database";$admin_user = "shaxs";$admin_password = "test";?>
====================
How I need it to look:
<?
## Pages Per Page
$perpage = 10;
$description_length = 150;
## MySQL
$server = "localhost";
$user = "shaxs";
$password = "password";
$database = "db_database";
$admin_user = "shaxs";
$admin_password = "test";
?>Read the PHP Manual on Double quoted strings (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double">http://www.php.net/manual/en/language.t ... tax.double</a><!-- m -->), in particular the part about escaped characters.Thank you for your reply. I must say I am a beginner at php. I am trying to edit code for a program I paid someone for, but it didn't work, so they did not get their money.
I tried using the /n option, but I may not have written the syntax right. How would the code look like for a line?
$f .= '$' . 'perpage = '.$pages.';' \n;
On that note, what is a good boox for starting out with php and mysql?It should be written as:
$f .= '$perpage = ' . $pages . ";\n";
Basically, "\n" is what you're looking for.
'\n' prints out a literal string '\n', but "\n" prints out a newline character, which is non-printable, I suppose
On that note, what is a good boox for starting out with php and mysql?
Try Paul Hudson's online book, Practical PHP Programming (<!-- m --><a class="postlink" href="http://www.hudzilla.org/phpbook/">http://www.hudzilla.org/phpbook/</a><!-- m -->).Thanks! I fiddled a bit and got it to write correctly. Now I just need to have a message display "You have successfully completed the setup. Please go here to access the admin page" once the setup form is submited and all validation is successful. Currently it goes to a blank page.
Any good website that shows how to display a message if the code is executed properly?something like this perhaps
// Set a flag to true at the top of the validation code.
// at each validation step set the flag to false if it fails and (optionally) jump out of validation.
// then at the end of validation test the flag and send a message or (better in my opinion) redirect the browser.
// validation flag
$valid_flag=true;
// validation tests
if( !$test )
{
$valid_flag=false;
}
// next test
if( !$test )
{
$valid_flag=false;
}
// end of validation
// test that all passed
if($valid_flag)
{
$msg="Success! Click <a href=http://www.phpbuilder.com/board/archive/index.php/"url">here</a>";
}else{
$msg="Failed! Go <a href=http://www.phpbuilder.com/board/archive/index.php/"url">back</a>";
}
// report to user
echo $msg;
or the final part could just redirect to a new page using the header() (<!-- m --><a class="postlink" href="http://www.php.net/header">http://www.php.net/header</a><!-- m -->) function.
I have the following code below. When I run the setup.php that contaisn this code, it writes to a file. But, the output written to the file is in one long line. I need it to put breaks in between each line. What do I need to add to the following code to get it to output the information right?
Here is the code that writes to the file:
write_config($_POST['host'],$_POST['user'],$_POST['password'],$_POST['table'],$_POST['perpage'],$_POST['description'],$_POST['admin_user'],$_POST['admin_password']);
}
function write_config($host,$user,$password,$table,$pages,$des,$admin_user,$admin_password){
$fp = fopen('port.config.php', "w");
if(!$fp){
setup_index('Unable to open port.config.php Try Chmoding it 777');
}
$f .= '<?';
$f .= '## Pages Per Page';
$f .= '$' . 'perpage = '.$pages.';';
$f .= '$' . 'description_length = '.$des.';' ;
$f .= '## MySQL';
$f .= '$' . 'server = "'.$host.'";' ;
$f .= '$' . 'user = "'.$user.'";' ;
$f .= '$' . 'password = "'.$password.'";';
$f .= '$' . 'database = "'.$table.'";';
$f .= '$' . 'admin_user = "'.$admin_user.'";';
$f .= '$' . 'admin_password = "'.$admin_password.'";' ;
$f .= '?>';
fwrite($fp, $f);
fclose($fp);
}
========================
This is how the ouput file looks:
<?## Pages Per Page$perpage = 10;$description_length = 150;## MySQL$server = "localhost";$user = "shaxs";$password = "password";$database = "db_database";$admin_user = "shaxs";$admin_password = "test";?>
====================
How I need it to look:
<?
## Pages Per Page
$perpage = 10;
$description_length = 150;
## MySQL
$server = "localhost";
$user = "shaxs";
$password = "password";
$database = "db_database";
$admin_user = "shaxs";
$admin_password = "test";
?>Read the PHP Manual on Double quoted strings (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double">http://www.php.net/manual/en/language.t ... tax.double</a><!-- m -->), in particular the part about escaped characters.Thank you for your reply. I must say I am a beginner at php. I am trying to edit code for a program I paid someone for, but it didn't work, so they did not get their money.
I tried using the /n option, but I may not have written the syntax right. How would the code look like for a line?
$f .= '$' . 'perpage = '.$pages.';' \n;
On that note, what is a good boox for starting out with php and mysql?It should be written as:
$f .= '$perpage = ' . $pages . ";\n";
Basically, "\n" is what you're looking for.
'\n' prints out a literal string '\n', but "\n" prints out a newline character, which is non-printable, I suppose
On that note, what is a good boox for starting out with php and mysql?
Try Paul Hudson's online book, Practical PHP Programming (<!-- m --><a class="postlink" href="http://www.hudzilla.org/phpbook/">http://www.hudzilla.org/phpbook/</a><!-- m -->).Thanks! I fiddled a bit and got it to write correctly. Now I just need to have a message display "You have successfully completed the setup. Please go here to access the admin page" once the setup form is submited and all validation is successful. Currently it goes to a blank page.
Any good website that shows how to display a message if the code is executed properly?something like this perhaps
// Set a flag to true at the top of the validation code.
// at each validation step set the flag to false if it fails and (optionally) jump out of validation.
// then at the end of validation test the flag and send a message or (better in my opinion) redirect the browser.
// validation flag
$valid_flag=true;
// validation tests
if( !$test )
{
$valid_flag=false;
}
// next test
if( !$test )
{
$valid_flag=false;
}
// end of validation
// test that all passed
if($valid_flag)
{
$msg="Success! Click <a href=http://www.phpbuilder.com/board/archive/index.php/"url">here</a>";
}else{
$msg="Failed! Go <a href=http://www.phpbuilder.com/board/archive/index.php/"url">back</a>";
}
// report to user
echo $msg;
or the final part could just redirect to a new page using the header() (<!-- m --><a class="postlink" href="http://www.php.net/header">http://www.php.net/header</a><!-- m -->) function.