Jump to content

Associating images to operation id in one form


josephman1988

Recommended Posts

Hey guys,

 

I have this form, which uploads data to a table, then uploads a file to the server, and also stores that information into another table.

What happens is it creates a page that shows both of these inputted files/data.

 

My DB tables:

 

operation_data

--------------------

| oid | name | date |

--------------------

 

screenshot_operation

---------------------------------------

| sid | name | title | operation_dataoid |

---------------------------------------

 

Form:

<form enctype="multipart/form-data" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
Case Name:<br />
<div id="operationupload">
<input type="text" title="casename" name="casename" /></div><br /><br />
Briefing:<br />
<div id="operationupload">
<textarea cols="50" rows="10" name="briefing" title="briefing"></textarea></div><br /><br />
Upload Screenshot:<br />
<div id="operationupload">
<input type="text" name="pictitle" title="pictitle" /><br />
<input type="file" name="imageupload" title="imageupload" />
</div>
<br />
<input type="submit" value="Submit" name="submit"  /> <input type="reset" value="Reset" name="reset" />

</form>

 

PHP Code:

<?php 

if (isset($_POST['casename'], $_POST['briefing'])) 
{
$casename = $_POST['casename'];
$briefing = $_POST['briefing'];
$pictitle = $_POST['pictitle'];
$picname = $_FILES['imageupload']['name'];

$sql = ("INSERT INTO operation_data SET
name = '$casename',
briefing = '$briefing',
date = CURDATE()");
if (@mysql_query($sql))
{
}else{
	 echo "Cannot Be Added, Something Went Wrong!";
	 }


$sql2 = @mysql_query("INSERT INTO screenshot_operation SET
	 name = '$picname',
	 title = '$pictitle',
	 date = CURDATE()");


if ( isset( $_FILES['imageupload'] ) ) {

$_FILES['imageupload']['name']; 
$_FILES['imageupload']['size'];
$_FILES['imageupload']['tmp_name'];
$_FILES['imageupload']['type'];   
$_FILES['imageupload']['error'];
basename($_FILES['imageupload']['name']);

$source = $_FILES['imageupload']['tmp_name'];
$target = "../images/operations/screenshots/".$_FILES['imageupload']['name'];



if($_FILES['imageupload']['type'] == "image/pjpeg" || $_FILES['imageupload']['type']=="image/jpeg")
		{

	}else{
	exit('Permission Denied, Please Only Upload mages');
	}

	if (file_exists($target))
		{
		exit( "File Name Exists, Please Alter" );
		} else  {
        			move_uploaded_file( $source, $target );
			echo "News Added. Thankyou!!";
			}
			}
}

?>

 

 

However, what I want to do, is associate this uploaded image to this very 'Operation'.

How would I go about it?

I thought putting the 'operation_dataoid in the screenshot_operation table, i would be able to grab that operations id i was adding  so in the template i could call the operations id from screenshot_operation table and display it.

 

Am i correct?

If not, how do I do this?

 

Thanks in advance, Joe.

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.