I have a function called create:
function create($table, $data)
{
global $conn;
$sql = "INSERT INTO $table SET ";
$i = 0;
foreach($data as $key => $value) {
if ($i === 0){
$sql = $sql . " $key=?";
} else{
$sql = $sql . ", $key=?";
}
$i++;
}
$stmt = executeQuery($sql, $data);
$id = $stmt->insert_id;
return $id;
}
And the executeQuery inside this function:
function executeQuery($sql, $data){
global $conn;
$stmt = $conn->prepare($sql);
$values = array_values($data);
$types = str_repeat('s', count($values));
$stmt->bind_param($types, ...$values);
$stmt->execute();
return $stmt;
}
The form that I try to submit with:
<form action="myedit.php" method="post">
<div class="input-group">
<label>Om mig</label>
<textarea class="text-input" name="about" id="john"></textarea>
</div>
<div class="input-group">
<button type="submit" name="change-about" class="btn">Ändra om mig</button>
</div>
</form>
and the code:
<?php
include(ROOT_PATH . '/app/database/db.php');
$table = 'about_me';
if(isset($_POST['change-about'])){
unset($_POST['change-about']);
$about = create($table, $_POST);
$_SESSION['message'] = 'innehåll ändrat';
$_SESSION['type'] = 'success';
header("location: " . BASE_URL . "/index.php");
exit();
}
Now the row in the database is named about. The table is named about_me. The function has worked fine in other files with other tables. The message gets displayed and I get redirected to index.php, but still nothing is in the row. The names are correct, so I'm at loss here.