Posted: Fri Mar 23, 2007 4:03 pm
I want a form that, once you press submit, writes down the data that you inputed, and records it to config.php in the same folder, so whenever your creating a webpage, you can include config.php, so you dont have to define the same variable again and again.
I fixed the code i wrote before(sort of)
This is what i got after reading your responses. I am a php noob. all i know are constants, defining variable, echos and the really basic stuff. so any help that gets this to work will be appreciated.
also i wrote the following code a week ago, but it didnt work, so i created the script above, but here is the script that sort of works
And i get this result when i open config.php
i dont get the values i inserted in the form
I fixed the code i wrote before(sort of)
Code: Select all
//config_maker.php
<html>
<head>
<title>Configuration File Maker</title>
</head>
<body>
<center><h3>Configuration file Maker</h3></center>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Site Title: <input type="text" name="site_title"><br>
Database Host(Usually Localhost): <input type="text" name="db_host"><br>
Database Username: <input type="text" name="db_user"><br>
Database Password: <input type="password" name="db_pass"><br>
Database Name: <input type="text" name="db_name"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($_POST["submit"]))
{
$site_title = $_POST["site_title"]; // Site title
$db_host = $_POST["db_host"]; // Database Host
$db_user = $_POST["db_user"]; // Database User name
$db_pass = $_POST["db_pass"]; // Database Password
$db_name = $_POST["db_name"]; // Database Name
}
$content = "<?php
define('site_title', '$site_title');
define('db_host', '$db_host');
define('db_user', '$db_user');
define('db_pass', '$db_pass');
define('db_name', '$db_name');
?>";
$file_to_write = "Config.php"
$fp = fopen($file_to_write, 'w');
fwrite($fp, $content);
fclose($fp);
echo "Success! <br>";
echo "$file_to_write";
echo " has been written";
?>
</body>
</html>also i wrote the following code a week ago, but it didnt work, so i created the script above, but here is the script that sort of works
Code: Select all
<?php
//Defining Variables
$site_name = $_POST["site_name"];
$site_title = $_POST["site_title"];
$db_host = $_POST["db_host"];
$db_user = $_POST["db_user"];
$db_pass = $_POST["db_pass"];
$db_name = $_POST["db_name"];
?>
<html>
<head>
<title>Config.php Maker</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="write" id="write">
Site Title
<input name="site_title" type="text" id="site_title">
<br>
Host
<input name="db_host" type="text" id="db_host">
<br>
Database User
<input name="db_user" type="text" id="db_user">
<br>
Database Password
<input name="db_pass" type="password" id="db_pass">
<br>
Database Name
<input name="db_name" type="text" id="db_name">
<br>
<input type="submit" name="Submit" value="Submit">
</form>
<?php
if ($_POST['Submit']) {
//Defining Variables
$site_title = $_POST["site_title"];
$db_host = $_POST["db_host"];
$db_user = $_POST["db_user"];
$db_pass = $_POST["db_pass"];
$db_name = $_POST["db_name"];
$file_to_write = 'Config.php';
$content = '<?php
define("site_title", "$site_title");
define("db_host", "$db_host");
define("db_user", "$db_user");
define("db_pass", "$db_pass");
define("db_name", "$db_name");
?>';
$fp = fopen($file_to_write, 'w');
fwrite($fp, $content);
fclose($fp);
echo "Success! <br>";
echo "$file_to_write";
echo " has been written";
}
?>
<br>
<a href="chmod.php">Chmod Config.php</a><br>
<a href="delete.php">Click Here to Delete Config.php</a>
</body>
</html>Code: Select all
//delete.php
<?php
$myFile = "config.php";
unlink($myFile);
echo " $myFile deleted";
?>
<html>
<head>
<title>Config.php Delete</title>
</head>
<body>
<a href="config_maker.php">Go Back</a>
</body>
</html>Code: Select all
//chmod.php
<?php
$file = "config.php"
chmod("config.php", 0777);
echo "$file chmoded";
?>
<html>
<head>
<title>Config.php Chmod</title>
</head>
<body>
<a href="config_maker.php">Go Back</a>
<a href="delete.php">Click Here to Delete Config.php</a>
</body>
</html>Code: Select all
<?php
define("site_title", "$site_title");
define("db_host", "$db_host");
define("db_user", "$db_user");
define("db_pass", "$db_pass");
define("db_name", "$db_name");
?>