我需要将值'0'放在数据库中,而不必填写文本字段。
当我在数据库中保存表单时,有没有办法给列赋值'0'? 这是形式:
<form action="<?php echo $base_url; ?>" method="post" enctype="multipart/form-data">
<table class="sug" width="300">
<tr><td><input type="text" name="naam" placeholder="Naam" required></td>
<td><input type="text" name="level" placeholder="Level"></td></tr>
<tr><td colspan="2"><textarea placeholder="Beschrijving" name="beschrijving" maxlength="200"></textarea></td></tr>
<tr><td><input type="file" name="afbeelding" required id="afbeelding"></td></tr>
<tr><td><input type="submit" name="add" value="Toevoegen"/>
</td></tr>
</table>
</form>
保存功能:
if (!empty($post_array)) {
// Check the add form:
$add = FALSE;
if (isset($post_array['add'])) {
// Save images
$check = getimagesize($_FILES["afbeelding"]["tmp_name"]);
if ($check !== false) {
//echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Upload afbeelding
$projecten->upload($_FILES['afbeelding']);
// Save project
$result = $projecten->save($post_array);
if ($result) {
// Save was succesfull
$add = TRUE;
} else {
// Indicate error
$error = TRUE;
}
}
}
public function save($input_array) {
global $wpdb;
// Insert query
$wpdb->query($wpdb->prepare("INSERT INTO `" . $wpdb->prefix . "ivs_canvas_tabel`
( `naam`, `level`, `beschrijving`, `afbeelding`)" .
" VALUES ( '%s', '%s', '%s', '%s');", $input_array['naam'], $input_array['level'], $input_array['beschrijving'], $_FILES['afbeelding']['name']));
// Error ? It's in there:
if (!empty($wpdb->last_error)) {
$this->last_error = $wpdb->last_error;
return FALSE;
}
return TRUE;
}
我不知道如何添加该字段,我希望有人可以帮助我!
您诚挚的
答案 0 :(得分:0)
您可以使用表单中隐藏属性的输入执行此操作:
<input type=“hidden” name=“colom” value=“0” />
答案 1 :(得分:0)
您可以在数据库中输入默认值:
alter table `table_name`
modify column `column_name` int default 0;