Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6033003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:25:12+00:00 2026-05-23T05:25:12+00:00

In the script below, you will see a value that is submitted in the

  • 0

In the script below, you will see a value that is submitted in the form titled “shorturl.” Ultimately I would like to take that value and use it to generate a unique URL that displays all of the submitted data from the form.

Here is the form where a user will submits the data:

    <html>
    <body>

    <p>Required fields are <b>bold</b></p>

    <form action="contact.php" method="post">
<p><b>Author's Name:</b> <input type="text" name="author" /><br />
<p>Company Name: <input type="text" name="company" /><br />
<p>Address:<br /><textarea name="address" rows="5" cols="40"></textarea></p>
<p>Phone Number: <input type="text" name="phone" /><br />
<b>Title:</b> <input type="text" name="title" /><br />
<p><b>One Word Description:</b> <input type="text" name="shorturl" /><br />
<p><b>Full Description:</b><br />
<textarea name="comments" rows="10" cols="40"></textarea></p>

<p><input type="submit" value="submit"></p>

<p> </p>

</form>

</body>
</html>

The next bit of code is the contact.php page that will output the user data:

<?php


/* Check all form inputs using check_input function */
$author = check_input($_POST['author'], "Enter your name");
$company = check_input($_POST['company']);
$address = check_input($_POST['address']);
$phone = check_input($_POST['phone']);
$shorturl = check_input($_POST['shorturl'], "Provide a single word description");
$title  = check_input($_POST['title'], "Write a title");
$comments = check_input($_POST['comments'], "Provide a full description");




/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
    show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<b>Please correct the following error:</b><br />
<?php echo $myError; ?>

</body>
</html>
<?php
exit();
}
?>

<head>
    <title><?php echo $_POST['title']; ?></title>
</head>
<body>

<p>
<b><?php echo $_POST['title']; ?></b><br>
Created by:<br> 
<?php echo $_POST['author']; ?><br>
<?php echo $_POST['company']; ?><br>
Contact: <br>
<?php echo $_POST['phone']; ?><br>
<?php echo $_POST['address']; ?><br>
Flyer Description: <br>
<?php echo $_POST['comments']; ?><br>
</p>

</body>
</html>

As you will see if you run this form, the function is pretty basic. Here is where I need the assistance. In the initial form the “shorturl” value is taken. The function of the shorturl value is as follows:

If this form was hosted on examplesite.com, then I would ultimately like for the form that is created to be available with submitted answers at examplesite.com/shorturl

First of all, how do I verify that this is in fact a single word via PHP? If a user submits the shorturl value as “House” then I need the form to return the value as true, but if the user submits “Big House” then the value is false and they need to alter the value to something that is acceptable such as “BigHouse”

Secondly, I need to verify that the shorturl value is unique to the site. In other words, once a shorturl has been used, that value needs to be sent to the MySQL database so that it will not be replicated by another user. To continue our example, if someone already had “House” as their shorturl value then the full URL of examplesite.com/House is already taken. Then if a new user comes and tries to use “House” the submission will produce an error message that says the name is taken.

And finally, how do I get all of this information to auto-generate a unique webpage with the form results? For an example let’s continue examplesite.com/House
Right now, when a user submits the form, the data is displayed on examplesite.com/contact.php. How do I generate a URL which would display the form data and be unique as defined by the shorturl and be viewable to a third party site visitor without submitting new data?

Wow. I hope that all makes sense.

I know there are several questions in here, so if you can only assist with one step that is fine. If you can tackle this entire issue then more power to you 🙂

I have done a fair amount of research on this and I am thinking that the first 2 questions should be able to be solved with PHP, but the third might involve a mod_rewrite function of some sort. I cannot thank you enough for getting this far with my query and many many thanks if you can provide a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:25:12+00:00Added an answer on May 23, 2026 at 5:25 am

    This should do a good job of verifying $shorturl:

    if (preg_match('/[^a-z0-9]/i', $shorturl)) {
        // $shorturl contains characters other than just numbers or
        // letters such as a tab, space, or special chars you probably don't want
    }
    

    As for making sure the url is unique:

    if (!mysql_num_rows(mysql_query("SELECT id FROM contact WHERE url = '$shorturl' LIMIT 1")) {
        // it is unique, yay    
    }
    

    And you would insert the urls like so:

    mysql_query("INSERT INTO contact (url) VALUES ('$shorturl')");
    

    As for autogenerating the content, that shouldn’t be that tricky. First, you will need to insert all the form data into the database, I would do this at the same time you insert the url. For dynamically retrieving the data, (using such a short url) you will need to do a tiny bit of .htaccess modification.

    Here is an example of what your .htaccess might look like for a user to be able to go to domain.com/shorturl while the actual scripts being ran (and what they will see) are at domain.com/contact.php?short_url=shorturl

    RewriteEngine on  
    
    # don't rewrite if the file exists
    RewriteCond %{REQUEST_FILENAME} !-f
    # don't rewrite if the directory exists
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)$ contact.php?short_url=$1
    

    At this point the rest is just capturing the GET variable as $_GET[‘short_url’] within contact.php (or anywhere you want this script to reside, as long as you change the RewriteRule accordingly) and returning the rest of the the information you captured using database queries, maybe something like:

    $short_url = mysql_real_escape_string($_GET['short_url']);
    
    $sql = "SELECT * FROM contact WHERE url = '$short_url'";
    $user_data = mysql_fetch_array(mysql_query($sql));
    
    extract($user_data);
    // with extract, all of $user_data's keys are now variables and their respective values
    // are contained within those variables
    // $user_data['company'] now becomes simply $company, for example
    
    echo "Company: $company";
    // etc...
    

    I hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The script below illustrates a capability of set and frozenset that I would like
If you view the jquery code below you will see the famous $(document).ready(function(){ that
I have a array which contains values like this See below for script sample
The script below will replace selected word in a textarea. But it only works
Consider the script below. It will launch two subprocesses, each one a CherryPy app
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
Given the script below that fetches words in another language and makes a connection
The script below, test.php, is intended to be placed in a specific directory of
The script below resides in my theme's functions.php file. It is designed to show
The script below worked on my Mac OS X. I'm now using Ubuntu OS,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.