Jump to content

[SOLVED] Create a new page


adam291086

Recommended Posts

Hello,

 

i am currently planning a new content management system, a very simple one for a uni project. I plan to have the page content and links called from a database using mysql and php. The problem is how to create a new page?? This will have to automatically update the links on all pages. Which wont be hard as to get the links i can set up each page to automaically select * from the links table.

 

But how do i create a new page in the first place and populate it with the correct content. I just need some ideas so help get me started.

 

Thanks

Link to comment
Share on other sites

Just mouse over on this forums navigation (on the links above) you will see how the value is being passed

 

http://www.phpfreaks.com/forums/index.php?action=help
http://www.phpfreaks.com/forums/index.php?action=search
http://www.phpfreaks.com/forums/index.php?action=profile

 

like this and you can do like Perad's post above

if ($_GET['action'] == help) {
// Add PHP for help page here.
}

Link to comment
Share on other sites

Its not out of your league, it just needs some more thought. Lets say the user wants to add a new page. The page contains a title and some content.

 

Database Table called pages

 

The user enters page title and content which is stored into the pages table.

 

$title = escape_string($_GET['page']);

$sql = "SELECT * FROM pages WHERE title='$title'";

$result = mysql_query($sql);

 

if (mysql_fetch_rows($result) != 0) {

$title = $row['title'];

$content = $row['content'];

}

 

The above code can be improved but you should get the idea.

Link to comment
Share on other sites

yeah i have the idea now. Only two more questions

 

1) How the hell will i create a function to create a new page. I.e with the basic css template done and links added.

2) How do i set the URL to say www.john.com/page=news

 

1) You could use something like Smarty. Smarty allows you to create HTML templates then assign php variables to the template. This allows you to create clean and structured and code. If you do not want to do that then create a new file. page.php

 

page.php should be a html page. Instead of having the title and content you would have <?php $title ?> and <?php $content ?>

 

After you have called the data from the database and assigned them to $title and $content variables you can include the page.php which will then assign the variables to the page.php file.

 

2) Here is one way. After executing this code you can just print out the array where you need it.

 

// Get title from database

while ($row = mysql_fetch_assoc($result) {

$navigationarray[] = '<a href="index.php?page=$row['title']">$row['title']</a>';

}

Link to comment
Share on other sites

thanks that really helpfull. One more thing then thats it. I see how to make a new page. But how would i go about creating a button that a user can click and a new page is automatically created? By created i mean a blank page showinging the basic page without any content. Then they enter in the conent through the form and the page is then populate with some information.

 

take page.php for example. To get the content it will be using an page ID to search the database for the content and will get page id from the url. How can i get this blank page created?

 

This may be a little confusing.

Link to comment
Share on other sites

Your missing the whole point. The pages don't actually exist! This is the entire point of a dynamic website. Do you think every time a new thread is started on this forum a new page is created?

 

You simply make a page with the forms to fill out, the user fills in the forms hits submit and the data is inserted into the database.

 

To view the page you then call a view.php file and pass it the id through the url.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.