rahulvicky00 Posted December 3, 2011 Share Posted December 3, 2011 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 More sharing options...
phpfreak Posted December 3, 2011 Share Posted December 3, 2011 I think it's the fact that you single quoted $file. Change: $file = '$result' . '.php'; to: $file = $result. '.php'; Link to comment https://forums.phpfreaks.com/topic/252360-auto-generated-pages-in-php/#findComment-1293776 Share on other sites More sharing options...
rahulvicky00 Posted December 3, 2011 Author Share Posted December 3, 2011 I think it's the fact that you single quoted $file. Change: $file = '$result' . '.php'; to: $file = $result. '.php'; Thank You for your reply..i have tried it but its not working...creating a page as "Resource id #3.php" Link to comment https://forums.phpfreaks.com/topic/252360-auto-generated-pages-in-php/#findComment-1293780 Share on other sites More sharing options...
Errant_Shadow Posted December 3, 2011 Share Posted December 3, 2011 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? Link to comment https://forums.phpfreaks.com/topic/252360-auto-generated-pages-in-php/#findComment-1293846 Share on other sites More sharing options...
scootstah Posted December 3, 2011 Share Posted December 3, 2011 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); } Link to comment https://forums.phpfreaks.com/topic/252360-auto-generated-pages-in-php/#findComment-1293945 Share on other sites More sharing options...
Errant_Shadow Posted December 4, 2011 Share Posted December 4, 2011 The script is cycling through many rows, so that will make a file with the name of the last row returned. Link to comment https://forums.phpfreaks.com/topic/252360-auto-generated-pages-in-php/#findComment-1294378 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.