I have the following form:
<!DOCTYPE html>
<html>
<head>
<title>Update Notifications</title>
</head>
<body>
<form enctype="multipart/form-data" action="update1.php" method="post">
<fieldset>
<legend>Enter Date and Notification, select the requisite categories</legend>
HOD<input type="checkbox" name="update[]" id="update" value="ihod"><br>
CR<input type="checkbox" name="update[]" id="update" value="icr"><br>
Non Teaching Staff<input type="checkbox" name="update[]" id="update" value="intstaff"><br>
Teaching Staff<input type="checkbox" name="update[]" id="update" value="itstaff"><br>
FE<input type="checkbox" name="update[]" id="update" value="ife"><br>
SE IT<input type="checkbox" name="update[]" id="update" value="iseit"><br>
SE EXTC<input type="checkbox" name="update[]" id="update" value="iseextc"><br>
SE COMPS<input type="checkbox" name="update[]" id="update" value="isecomp"><br>
TE IT<input type="checkbox" name="update[]" id="update" value="iteit"><br>
TE EXTC<input type="checkbox" name="update[]" id="update" value="iteextc"><br>
TE COMPS<input type="checkbox" name="update[]" id="update" value="itecomp"><br>
BE IT<input type="checkbox" name="update[]" id="update" value="ibeit"><br>
BE EXTC<input type="checkbox" name="update[]" id="update" value="ibeextc"><br>
BE COMPS<input type="checkbox" name="update[]" id="update" value="ibecomp"><br>
Notification: <input type="file" name="photo"><br>
Date: <input type="text" name="date"><br>
<input type="submit" name="Submit">
</fieldset>
</form>
</body>
</html>
My update1.php contains the following code:
<?php
if (isset($_POST['table']) && isset($_POST['date']) && isset($_POST['pic']) && isset($_POST['target'])){
$target = "notifications/"; //This is the directory where images will be saved
$target = $target . basename( $_FILES['photo']['name']);
$date=$_POST['date'];
$pic=($_FILES['photo']['name']);
mysql_connect("127.0.0.1", "root", "") or die(mysql_error()) ;
mysql_select_db("login") or die(mysql_error()) ;
foreach ($_POST[$name] as $update) {
if($update == $value){
$table = $_POST[$name];
mysql_query("INSERT INTO `$table` VALUES ('$date', '$pic')") ;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file."; }
}
}
}
What I want to do is to store data into tables (which have already been created in a "login" database with names corresponding to checkbox values). After the checkboxes have been ticked, I would like the program to automatically update the corresponding tables with the necessary values (i.e. date and filename). I am currently confused with the foreach() syntax and how it really works. Also, can implode be used for this purpose?
PS: Is it possible to accept values using the tag in the form and store it into the database using the following method?