I have no idea what I need to do to make this function. After the update button has been pressed on this page, the contact's information should be updated. The information is read from the database and entered into the page along with the ID number as values. The inputs are then updated as necessary, and the server is updated. However, for some reason, the Update statement is not being executed, and nothing is changing. It should also be able to upload an image and make it part of the update.
This is my database:
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'project');
/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
This is my form:
<form method="post" action="action/update-certificate.php?id=<?php echo $_GET['viewid']?>" class="main-right" id="mainbar" enctype="multipart/form-data">
<div class="grid-3">
<div class="grid-item">
<p class="grid-title">certificate of employment signature</p>
<input type="file" name="coe_signature" class="cert-int">
</div>
</div>
<button class="btn-add" type="submit" name="update_certificate"></button>
</form>
This is my code:
<?php
include '../../../config.php';
if (isset($_POST['update_certificate'])) {
if (isset($_POST['coe_signature'])) {
$file = $_FILES['coe_signature'] ?? "";
$filename = $_FILES['coe_signature']['name'] ?? "";
$fileTmpName = $_FILES['coe_signature']['tmp_name'] ?? "";
$fileSize = $_FILES['coe_signature']['size'] ?? "";
$fileError = $_FILES['coe_signature']['error'] ?? "";
$fileType = $_FILES['coe_signature']['type'] ?? "";
$fileExt = explode('.', $filename);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 5000000000000000) {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$coe_signature = $_POST['coe_signature'];
$coe_signature_sql = "UPDATE certficate SET coe_signature = '".$coe_signature."' WHERE viewid = ".$_GET['id']." ";
mysqli_query($link, $coe_signature_sql);
}
else{
echo "Your file is too big";
}
}
else{
echo "There was an error uploading your file";
}
}
else{
echo "Cannot upload this file type";
}
}
}
else{
echo "ERROR contact the developer";
}
?>