Jump to content

Creating a new php file from user submitted data


gengo

Recommended Posts

First project with php.  Not even sure if I will ask the correct questions, but I will certainly try.

 

Some of the background:

 

I have a site that allows users to register, then login, only users that are logged in can submit a form with a title, category, url and comments.  All of these are stored in a database which also includes a unique id for each submission (auto increment), the name of the user submitting, and a timestamp of when the submission occurred.  The main page, for users logged in and visitors not, displays one of these submissions at random, filling in the title, category, user who submitted, url, and comments.

 

All of the above works correctly.

 

But if a visitor or user comes across a submission that they really like, there is no way of returning directly to it - since it is randomized, they would have to refresh until it appeared again.

 

I want to create a page for this at the time of first submission.  I will have a special subfolder in the root directory for the new files, and I am fine with them being named "uniqueid".php.

 

I THINK I have found a way to create the new (blank) file:

 

$newfilename = $newid.".php";

 

$newfilehandle = fopen($newfilename,'w') or die("Can't open file");

 

I am not sure if that is correct, just what I found.

 

Thank you in advance for any and all help.

 

Also, if I have other questions about this same project, (using AJAX to check login and registration information) - it is protocol to keep all projects together, or start a new topic for a different area?

Link to comment
Share on other sites

From what I understand, you just want a way for users to be able to return to a post they liked, and since each post has a unique id, all you want to actually do is store those ids.

 

Why not create a new table in your database, with just id, userName, pageId and simply let them 'bookmark' the stuff they like?

 

of, store the last 40-50 topics per user in a session variable, so as long as they don't close the browser, they'll be able to navigate back to them.

 

Dunno if this is what you're looking for. Hope it helps

Link to comment
Share on other sites

Thank you for the reply.

 

I already have a field in the table for id.  It auto increments each time something is uploaded.

 

Right now, I have the index page set to select a random id, then populate the page with the other information from that row.  This works fine, except the URL is sitename.com/index.php

 

What I want is when someone creates a new submission (assigned behind the scenes = id, username, timestamp // created from user data = title, category, link, comments) - that it will create a whole new page "id.php", and populate THAT page with the other information from the row that was just created.

 

I can create a new php file (kinda, can't get it to be the id that I want), but I cannot figure out how to get all of the html/php formatting / information into that newly created page.

 

Again, I am so new (this is my first php / mysql project) that I am not sure I am using the correct terminology.

Link to comment
Share on other sites

Would you be able and willing to share how this is done?

 

Do you mean that each video IS contained in its own page, or that the video id in the URL will trigger which random page to load?

 

Again, sorry for my confusion.

Link to comment
Share on other sites

Basically, I pull out 50 random ids from the database and store them in a $_SESSION array, I use one at a time, removing it from the array once it's been used. This way they never repeat, and it's very easy to put them in the url. While the first video is being watched, I've already created the link for the second one, so that when someone pressed 'random', it's already in 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.