我不知道我的头衔是否正确,有人可能会将其编辑为正确的内容
麻烦:
我已经在表单中创建了一个下拉菜单,它的工作方式如下:
然后现在我想更改下拉表单以显示每个下拉数据,而不显示下拉列表:
但是我更改表单后按钮不起作用,
这是我要展示和执行的代码:
<form method="post">
<div class="form-group">
<label for="ia">Alternatif</label>
<select class="form-control" id="ia" name="ia">
<?php
$stmt3 = $pgn1->readAll();
while ($row3 = $stmt3->fetch(PDO::FETCH_ASSOC)){
extract($row3);
echo "<option value='{$id_alternatif}'>{$nama_alternatif}</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="ik">Kriteria</label>
<select class="form-control" id="ik" name="ik">
<?php
$stmt2 = $pgn2->readAll();
while ($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)){
extract($row2);
echo "<option value='{$id_kriteria}'>{$nama_kriteria}</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="nn">Nilai</label>
<input type="text" class="form-control" id="nn" name="nn">
</select>
</div>
<button type="submit" class="btn btn-primary">Simpan</button>
<button type="button" onclick="location.href='rangking.php'" class="btn btn-success">Kembali</button>
</form>
//for display item as list im change <label for="ik">Kriteria</label> code
<div class="form-group">
<form class="form-control" id="ik" name="ik">
<?php
$stmt2 = $pgn2->readAll();
while ($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)){
extract($row2);
?>
<option value="<?php echo $id_kriteria; ?>"><?php echo $nama_kriteria; ?></option>
<input type="text" class="form-control" id="nn" name="nn">
<?php
}
?>
</form>
</div>
我使用此代码在与表单文件相同的文件中执行按钮:
<?php
if($_POST){
include_once 'includes/rangking.inc.php';
$eks = new rangking($db);
$eks->ia = $_POST['ia'];
$eks->ik = $_POST['ik'];
$eks->nn = $_POST['nn'];
if($eks->insert()){
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Berhasil Tambah Data!</strong> Tambah lagi atau <a href="rangking.php">lihat semua data</a>.
</div>
<?php
}
else{
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Gagal Tambah Data!</strong> Terjadi kesalahan, coba sekali lagi.
</div>
<?php
}
}
?>
任何人都可以帮助我吗?
修改 的
这是执行按钮的if($eks->insert())
代码:
function insert(){
$query = "insert into ".$this->table_name." values(?,?,?,'','')";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $this->ia);
$stmt->bindParam(2, $this->ik);
$stmt->bindParam(3, $this->nn);
if($stmt->execute()){
return true;
}else{
return false;
}
}
答案 0 :(得分:0)
尝试更改按钮类型以提交&#39;。
{{1}}