Config.php maker NEED HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

Code: Select all

$content = '<?php   // single quote not double
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");
?>';// end single quote not double
I used this code

Code: Select all

$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");
?>';
but i still get

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");
?>
in config.php
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

ziggy3000 wrote:

Code: Select all

$content = '<?php   // single quote not double
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");
?>';// end single quote not double
I used this code

Code: Select all

$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");
?>';
but i still get

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");
?>
Do you not comprehend me or the website change the ' and the ' to " and "

Example:

Code: Select all

$text = 'Hello... message here';
// Example 1:
   $message = '$text';
   Echo $message;
   // Outputs
   // $text

// Example 2:
   $message = "$text";
   Echo $message;
   // Outputs
   // Hello... message here
Last edited by tecktalkcm0391 on Fri Mar 23, 2007 6:09 pm, edited 1 time in total.
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

oh... i thought it was the other way around... sorry.
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

now i am getting this error

Code: Select all

Parse error: parse error, unexpected T_STRING in C:\Server\Apache\htdocs\Config_maker.php on line 47
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

ziggy3000 wrote:oh... i thought it was the other way around... sorry.
It's ok, just be careful cause one mistake can totally mess up your codes.
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

ziggy3000 wrote:now i am getting this error

Code: Select all

Parse error: parse error, unexpected T_STRING in C:\Server\Apache\htdocs\Config_maker.php on line 47
Can anyone help?

this is the code

Code: Select all

$content = "<?php  //46
define("site_title", "$site_title");  //47
define("db_host", "$db_host");  //48
define("db_user", "$db_user");  //49 
define("db_pass", "$db_pass");  // 50
define("db_name", "$db_name");  //51
?>";
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What are you trying to do with the $content var?
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

Again this is my code. i am trying to write $content to config.php

Code: Select all

//config_maker.php
<?php
<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> //works dont need help on it
<a href="delete.php">Click Here to Delete Config.php</a> //works, dont need help on it
</body>
</html>
Last edited by ziggy3000 on Fri Mar 23, 2007 6:46 pm, edited 1 time in total.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

I think it may just be time to buy a book...

Code: Select all

$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 . '");
?>';
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

i'm going to get a big fat book this weekend. :)

Oh and thank you so much, it works! 8)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Ziggy, have a read up on strings in PHP. Your quotes were killing you on this one.
Post Reply