I'm trying to update the records whereby I found out that I will be doing alot of If-Else Statements for checking. For example, now i have 4 upload buttons inside my form. If the document has been attached, there would not be any upload button. But it is updated to the database, it will show errors because the user did not attached any document. Maybe I'll explain out in my code and will give a clearer picture.
Code for my form:
<form id = "update" action ="update.php">
//Code is repeated for all upload and download buttons just that one is for test, assign, and papers
<?php
if ($Attached== "No")
{
echo "<select name=\"Test\" id=\"Test\">";
echo "<option value=\"No\" selected=\"selected\">No</option>";
echo "<input name=\"Attached[test]\" id=\"Test\" type=\"file\"/>";
echo "</select>";
}
else
{
Button to download the document
$fullpath = "./documents/."$Test";
echo "<input type=\"hidden\" name=\"fullpath\" value=\"$fullpath \"/>";
echo "<input type=\"submit\" name=\"download\" value=\"download\"/>";
}
?>
</form>
Update.php code:
//So if i wish to update into my database sqlite3, i'll need to check as follows:
$test = $_POST['Attached[test]'];
$ID = 1;
$DB = = new PDO('sqlite:database/Test.DB');
If ($test != "")
{
$update = $DB->prepare('update test set test =?, assign =?, papers =?);
$execute = $update-> execute (array($test, $assign, $paper));
}
else if ($test == $test)
{
$update = $DB->prepare('update test set assign =?, papers =? where ID=?);
$execute = $update-> execute (array($assign, $paper));
}
else
{
moveuploaded_files();
}
So my question is how can i shorten my ife-else statement to check if the individual value actually exists in database already and don't update that particular column(s). Kindly advise thanks