Reputation: 356
I currently have a table called paper
, which holds all the information for each paper that a user uploads to my system. I also have a table called paper_topics
; this is meant to hold the paper_id
and its topic_id
from a table called topic
. However I'm not sure how I can use PHP to allow the user to select multiple topics and then submit them along with the paper_id
to the paper_topics
table.
Here is the code I have for uploading the paper.
if(!is_dir("paper")) {
mkdir("paper");
}
function savedata(){
global $_FILES, $_POST, $putItAt;
$sql = "INSERT INTO `internetcoursework`.`paper` (
`paper_id`,
`username`,
`title`,
`abstract`,
`filelocation`,
`date_added`)
VALUES (NULL,'".mysql_real_escape_string($_POST['username'])."' , '".mysql_real_escape_string($_POST['title'])."',
'".mysql_real_escape_string($_POST['abstract'])."', '".mysql_real_escape_string($putItAt)."', CURDATE());";
mysql_query($sql);
}
$putItAt = "paper/".basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FIleS['uploadedfile']['tmp_name'],$putItAt)) {
savedata();
header("location: listfiles.php");
echo "you have succesfully uploaded";
}else {
if(copy($_FILES['uploadedfile']['tmp_name'],$putItAt)) {
savedata();
header("location: listfiles.php");
} else {
echo "you totally failed";
}
}
?>
'
Upvotes: 0
Views: 99
Reputation: 2317
If I understand your request correctly ("select multiple topics and then submit them along with the paper_id to the paper_topics table") the basic idea is to add a multi select form element to your form (like this http://onlinetools.org/tricks/using_multiple_select.php), then use that posted value to insert rows into the paper_topics table. You'll need to insert the paper and get the paper id first ( http://php.net/manual/en/function.mysql-insert-id.php )
Does that answer your question?
Upvotes: 1