Jump to content

auto generated pages in php


rahulvicky00

Recommended Posts

Hi Mates,

 

I want to know how to create auto generated pages in submit button with the existing templates...Wordpress users may easily understand what actually i mean...i am using the code that is creating a page but not getting the desired page name and giving a blank page that is without any formatting...

 

<?php
$content = <<<EOL
<head>
</head>
<body>
New page
EOL;

include ('config.php');
mysql_select_db("$db_name");
$result = mysql_query("SELECT * FROM text ORDER BY ID")
or die(mysql_error());

while($row = mysql_fetch_array( $result )) {
echo $row['title'];
echo "<br />";
}

$content .= <<<EOL
</body>
</html>
EOL;
$file = '$result' . '.php'; 
$open = fopen($file, "w");
fwrite($open, $content);
fclose($open);
?> 

Link to comment
https://forums.phpfreaks.com/topic/252360-auto-generated-pages-in-php/
Share on other sites

Is $row['title'] what you want?

 

The result resource is not the data fetched by the query. You have to use mysql_fetch_array (or a similar function) to access the data. It is giving you "Resource id #3.php" because it has made a successful execution and is returning data.

 

I see you are looping through the results and printing each title, so I wonder what you are using to derive the name of the file you are making?

You'll need to do something like this:

$content .= <<<EOL
</body>
</html>
EOL;

while($row = mysql_fetch_array( $result )) {
echo $row['title'];
echo "<br />";

$file = $row['title'] . '.php'; 
$open = fopen($file, "w");
fwrite($open, $content);
fclose($open);
}


Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.