Jump to content

Multiple Forms Problems..


tkdiamond08

Recommended Posts

Hey all,

 

I'm pretty new to PHP, and I seem to be having trouble using multiple forms. I know there's probably a million other topics similar to this, but what i'm trying to accomplish isn't exactly common.

 

Anyways what I need is 3 values taken from a form with 3 separate inputs (1 a file upload, 1 a text field for the video name, and 1 a drop down list of subjects) and to store them for later use in my script (called upload_php2.php) after the submit button is hit. It looks right on the site, however it doesn't function properly. I got them each working separately with their own submit button, however that is definitely not how I want it to work.

 

Here's the php code that is on the upload page itself:

 

session_start();

$subjects = array('','Math', 'Science', 'Tech', 'Social Science', 'English');

if(isset($_POST['submit']) && $_POST['videoname'] != null)  {      # If this form has been submitted and the name is not null
$_SESSION['name'] = $_POST['videoname'];    # Use what has been submitted
}

if(isset($_POST['submit']) && $_POST['subjs']!=0) {        # If this form has been submitted and the subject array value (1,2,3..etc) is not 0  (which means they didn't select it)
$_SESSION['subject'] = $subjects{$_POST['subjs']};    # Use what has been submitted
}

function showOptionsDrop($array, $active) {
$string = '';

foreach($array as $k => $v){
    if(is_array($active))
	$s = (in_array($k, $active))? ' selected="selected"' : '';
    else
	$s = ($active == $k)? ' selected="selected"' : '';
    $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n";     
}
    return $string;
}

 

And here's the html code on the upload page:

 

<form action="upload_file2.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<br />
<label for="file">Name your Video:</label>
<input type="text" value="" name="videoname" />
<br />
<br />
Select a Subject: 
<select name="subjs">
<?php echo showOptionsDrop($subjects, $_SESSION['subject']); ?>
</select>
<br />
<br />
<input type="submit" name="submit" value="submit" />
</form>

 

Any ideas?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/161852-multiple-forms-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.