Jump to content

PHP Form and Images?


cjenkins08

Recommended Posts

I'm pretty new to PHP, but I am wondering what would be the easiest way to accomplish this.

 

I am looking to have a form with two different lists(each list will have the name of one of the 50 states), the user will be able to select one state from each list.

 

Each state on the list will have a picture of the state that is accociated with it.

What is the easiest way to connect the name chosen with the image associated with it?

 

Should this be in a Database?

Should the images be stored direct or via a link to the URL of the images?

Could the images just be stored in an Array?

 

Using FPDF I have already styled a page, then I am then going to display the two state images in that same .pdf file.

Link to comment
Share on other sites

 

 

What is the easiest way to connect the name chosen with the image associated with it?

Give each image the name of the state. eg Alabama.png,  Ohio.png etc.

 

You'd set up your dropdown menu like

State:
<select name="state">
   <option>Alabama</option>
   <option>Alaska</option>
   <option>Arizona</option>
   ...
   <option>Wyoming</option>
</option>

You'd then link to the image using something like this

if(isset($_POST['state']))
{
    // load the state images stored in site.com/images/states into an array
    $state_images = glob('images/states/*.png');
    
    // get the associated image
    if(in_array($_POST['state'] . '.png', $state_images))
    {
        $state_image_path = '/images/states/'.$_POST['state'].'.png';
    }

    // display the associated image
    echo 'State Selected: ' . $_POST['state'] . '<br />State Image: <img src="'.$state_image_path.'" />';
}
Edited by Ch0cu3r
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.