I'm using MySqli to insert a piece of page-content into the database in the table content
with the following columns: id
, name
, content
, parent
, order
where content is of type TEXT
. The problem however is, that when executing the insert statement it does insert a new entry into the table, but does not insert the content
and the parent
value, while properly inserting the name
and order
value. I checked the return values of all the prepare functions and all returned true or gave no error so I'm extremely confused as to what is going on.
The class properties ($this->Content
and $this->Parent
) are filled and contain the proper data. Also, the update/edit
part of the function works just fine (seeing as the prepared functionality of both these parts is exactly the same, this is an odd error).
This is the code that performs the queries. the $type
variable can take two values: edit
or new
and when its new
it doesn't function properly.
public function Save($type)
{
if($type == "edit")
{
$query = "UPDATE `content` SET `name` = ?, `content` = ?, `parent` = ? WHERE `id` = ?";
$stmt = $this->sql->prepare($query);
$stmt->bind_param("ssii", $this->Name, $this->Content, $this->Parent, $this->ID);
}
else if ($type == "new")
{
$query = "INSERT INTO `content`(`name`, `parent`, `content`, `order`) VALUES(?, ?, ?, 999)";
$stmt = $this->sql->prepare($query);
$stmt->bind_param("ssi", $this->Name, $this->Content, $this->Parent);
}
if(!$stmt->Execute())
echo "Failed saving content-object with ID $this->ID" . mysqli_error($this->sql);
$stmt->close();
}
I have no idea why the edit
part works perfectly fine, but the new
part does not. The query does insert a new row with the correct name and order values, so I guess it has something to do with the bind_param
function. The row in the database always results with the value 0
for both content
and parent
.