1

The forums have been a huge help on this project so far. I'm looking for some guidance on the next step of my project here.

What I have is a form that feeds user submitted information into a MySQL database. This database then feeds this information to a main page displaying all of the information in the DB. What I am looking to do is add something to my form that creates a new unique URL/page when the form is submitted. I have already designed the HTML/CSS template for this page and it is designed to display only one set of information as opposed to the entire DB worth.

I am looking for some guidance as to how I can create the pages and unique URLs on the form submit. What is the best way to get this fresh information feeding from the DB immediately?

I need to somehow automatically recreate the HTML and CSS files as well on the server, this I am unfamiliar with.

EDIT: After @Jacky Cheng pointed out that this was possible without creating new versions of the HTML/CSS files I would be inclined to go about having a single HTML file on the server that is dynamic.

Thanks for any help as you guys have been great so far.

Including code for the form which I am submitting to the DB from, and the page which I will be pulling info from.

This is the form:

<?php
include_once 'post_func.inc.php';
connect();
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Event Register</title>
  </head>
  <body>
    <div style="text-align: center">
      <h2>Event Register</h2>
      <form id="eventregister"action="eventtestconnect.php" method="post">
        <table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
          <tr>
            <td>Event Name:</td>
            <td><input name="name" type="text"></td>
            </tr>
            <tr>
            <td>Event Type:</td> 
            <td>
                <select name="eventtype">
                    <?php query_eventtype() ?>
                </select>       
            </td>
          </tr>
            <tr>
          <tr>
            <td>Venue:</td>
            <td>
                <select name="venue">
                    <?php query_venue() ?>
                </select>                   
            </td>
          </tr>      
       </table>
       <input type="submit" value="Submit">
       </form>
    </div>
  </body>
  <?php close() ?>
</html>

This is the page I want filling with information from the DB after the form is submitted and the url is generated.

<?php
include_once 'event_func.inc.php';
connect();
?>
<html>
<head>
<title>
<?php query_eventname() ?>
</title>
<link href="eventstest.css" rel="stylesheet" type="text/css"/>
</head>
<body id="body">
  <div id="maincontainer">
    <div id="header">
    </div>
      <div id="content">
        <div id="eventname">
           <?php query_eventname() ?>
        </div>
        <div id="eventvenue">
           <?php query_eventvenue() ?>
        </div>
        <div id="eventicon">
           <?php query_eventtype() ?>
        </div>
      </div>
  </div>
</body>
<?php close() ?>
</html>

What changes need to be made to the form in order for the url to be generated on submit and the event page to be able to jump between urls/sets of data dynamically, per-say?

Sorry for the beginner questions but this site really seems to be the best resource for these sorts of things and I haven't found anything this specific on here!

Thanks again for the help!

velvetpuma
  • 103
  • 5
  • 15
  • I'm not sure to get what you want to achieve. What would the "unique URL" look like? Will using a random parameter in the query string suffice? – MaxArt Jul 16 '14 at 07:51
  • @MaxArt Yeah i believe it would, I was thinking of using the auto incremental id of the DB table that I was pulling from. so something along the lines of www.mydomain.com/12345 where the unique id is 12345. if the page was created in the "new" folder on the server it would be www.mydomain.com/new/12345. – velvetpuma Jul 16 '14 at 07:58

3 Answers3

2

I am still half guessing what you want, so bear with me here.

from the description of your question, you seems to have a system that would generate an actual html file per form submit? That doesn't look good to me. maybe try something like this :

redesign a web page that would take http GET request parameter as input (mydomain.com/display.php?id={input1}) and display only 1 set of info.

from the comments I see you have a unique id per form submit, I'd suggest avoid using it directly in the request as it'll be extremly easy to get someone else's info. Instead try somthing like MD5 encoding for that id and then sending that out to user.

so the overall system would be:

1) you'll only ever have 1 html file in your server, which will dynamically change it's content according to input, which save you a lot of space.
2) you'll have a unique & slightly more secure URL per form submit

edit: here are some fake code to show the general idea.

form response:

$uniqueId=mysql_query("SELECT unique_id FROM my_db");
echo "http://yourdomain.com/display.php?urlid=".$uniqueId;

display.php

<?php
$uniqueId=$_GET['urlid'];
mysql_query("SELECT info_you_need FROM your_tables WHERE unique_id = $uniqueId");
?>
<html><body>your display page html here</body></html>
Jacky Cheng
  • 1,536
  • 1
  • 10
  • 22
  • This is great! Really clearing things up for me, the whole 'create a new page per form submit' felt really messy. So this seems to make much more sense, I don't know much about the http GET request parameters and how that works. And as for the md5 encoding of the unique ID would I do that in PHP in conjunction with the `http_build_url` option? thanks for the help – velvetpuma Jul 16 '14 at 08:26
  • I believe that this function will convert my ID's to md5: `function url_gen(){ $uniqueid=mysql_query("SELECT unique_id FROM my_db"); $urlid=md5($uniqueid); }` but it seems that the `http_build_url` will not be working for my purposes after I've researched more. – velvetpuma Jul 16 '14 at 08:51
  • To be honest if this is more of a pratice project than encrypting is probably overkill. That said, if you still wanna try basic encryption then this is a good post to have a look at. http://stackoverflow.com/questions/16600708/php-string-encrypt-and-decrypt. Also, be aware that you need to have a way to decrypt your urlid when it is pass back from the client via GET request so that you could extract the unique id and use it to query DB. A simple MD5 encoding is "mostly" undecryptable – Jacky Cheng Jul 16 '14 at 08:55
  • Thanks! This is all great information, it is precisely where I want to go with the project. So i need to learn more about it. – velvetpuma Jul 16 '14 at 09:07
  • Do you have any resources about redesigning a webpage to take http GET request parameters as input? I am really hitting a brick wall on this front. The idea intrigues me and I think i get the jist of it, I just want to know how to implement it. It essentially means using the URL as the way of knowing what content to put on the page? But how do I generate the URL and how do I make the HTML/PHP page pull that information? I appreciate you bearing with the beginner questions! – velvetpuma Jul 16 '14 at 15:41
  • It's actually not that hard, you are stuck because you are probably looking at the wrong thing. The thing you need to search for is $_GET. I've added a mini example to demostrate the general idea. – Jacky Cheng Jul 17 '14 at 02:42
  • Took my beginner hands long enough but I managed to get this method working! Thanks for the help, I appreciate the guidance! – velvetpuma Jul 18 '14 at 00:09
0

I guess...

You want to create product catalog page like this:

www.abc.com/Electronics/Product-Motorola-moto-g-at-Rs6999-only.html

and this will display all the product information from the database.

If the above is your case then you can use url rewrite in your project.

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^Product-/?$    Product-Motorola-moto-g-at-Rs6999-only.html    [NC,L]           # Handle requests for "Product-"

The "RewriteRule" line is where the magic happens. The line can be broken down into 5 parts:

RewriteRule - Tells Apache that this like refers to a single RewriteRule. ^/Product/?$ - The "pattern". The server will check the URL of every request to the site to see if this pattern matches. If it does, then Apache will swap the URL of the request for the "substitution" section that follows. Product-Motorola-moto-g-at-Rs6999-only.html - The "substitution". If the pattern above matches the request, Apache uses this URL instead of the requested URL. [NC,L] - "Flags", that tell Apache how to apply the rule. In this case, we're using two flags. "NC", tells Apache that this rule should be case-insensitive, and "L" tells Apache not to process any more rules if this one is used.

Handle requests for "Product" - Comment explaining what the rule does (optional but recommended)

Hope this will work for you. Feel free to ask any help. Happy programming :)

Avtansh
  • 81
  • 1
  • 1
  • 9
  • Hey there, I added the apache tag to the post and edited it adding some of my current code and further questions. The method you show here. Is that something that I would do server end via apache2? Or would it be written into my page via PHP etc. ? and if it is on the server as I believe I am unclear on how I would prompt generating a new page/url on form submit. Sorry for the beginner questions but I really appreciate the help. – velvetpuma Jul 16 '14 at 15:05
  • You have so many ways to do so. Either you can specify it in .htaccess file or you can generate it on form submit. You want to do it on form submit so create a url string from the input tag like eventcategory-eventtype-eventvenu.html and save it in database. – Avtansh Jul 17 '14 at 06:21
0

Bear with me too. Your description is pretty bad. So if I am correct, you want form=>mysql=>confirmation

So, form should be action="process.php" method="post"

Create a process.php file where you do your validation, escaping, serializing, etc. Insert into the MySQL table. If returns true redirect (header(location:yourdomain.com)) and then on the redirected page, select the information from the Database.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
TalkingHeads
  • 130
  • 2
  • 11