Jump to content

Can this be done with PHP. My newbie learning project.


the-sexy-slug

Recommended Posts

Hello

 

This is what I am wanting to do can it be done in php without database or mysql?

 

Basically what I would like to do is from a seach box on my site I would like to take the search term that the user inputs into that search box and then place that seach term on a php page that is automatically generated with the filename search-term.php and is added to a sidebar. The keyword would also be placed on the webpage with a tag %searchterm% so I can have text "you searched for %searchterm%" and it will echo the users search term that they put into the search box.

 

Like I said I am new to php coding so this is a project that I would like to try. It will involve auto generating php files and auto adding links to pages  and keyword grabbing. I would like to do this with out mysql or databases.

Link to comment
Share on other sites

I would use the .htaccess (URL rewriting) to pull all search terms from the URL (if you're running an apache server), i.e. www.yourdomain.com/search/searchTermHere Here is a tutorial on .htaccess URL rewriting

Then use php to generate the page on demand and echo the search term...

 

What are you searching through? Pages in your site, or pages on external sites?

Without using a database I think you will be putting a lot of strain on your server unnecessarily...

Link to comment
Share on other sites

It would be a standard search form box on my site not any externam sites. What ever they put in that search box would then be made into a php page/file and linked to a sidebar file and echo the search term also in the generated page. Its a little project as I have seen a few flat file blogs etc that do not have this feature and I just thought it would be an interesting project to learn php with.

Link to comment
Share on other sites

have a look at this form tutorial to learn about forms

Then you'll have to (as Bradley99 said) set the form's action="search-term.php" and method="POST"

 

Then on search-term.php you can have code such as

//assuming the search text input is named 'searchTerm'
//check if searchTerm is being posted
if (isset($_POST['searchTerm'])) {
echo $_POST['searchTerm'];
//do whatever else you want if a search term is 
}

 

You can change the method to GET instead of POST, and the form input will be sent across in the URL such as

www.domain.com/search-term.php?searchTerm=bunny rabbit

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.