我有这段代码,但未能执行,请帮我解决这个问题
连接
<?php
$servername = "localhost";
$username = "root";
$password = "pwd";
$database = "cece";
// Create connection
$terhubung = new mysqli($servername,$username,$password, $database);
// Check Connection
if ($terhubung->connect_error) {
die ("connection failed: " . $terhubung->connect_error);
}
?>
这是编辑表格
<?php
include "conn.php";
$id = $_GET['no'];
$query_mysql = $terhubung->query("SELECT * FROM data222 WHERE id='$id'")or die(mysql_error());
$nomor = 1;
while($data = mysqli_fetch_array($query_mysql)){
?>
<form action="edit/edit_data222.php" method="post" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">ID</label>
<div class="col-md-1 col-sm-1 col-xs-12">
<input type="text" name="id" readonly="readonly" value="<?php echo $data['id']?>" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" >Nama PT</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="nama_pt" value="<?php echo $data['nama_pt']?>" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Barang</label>
<div class="col-md-4 col-sm-4 col-xs-12">
<select name="brg" class="select2_single form-control" tabindex="-1">
<option value="">Pilih...</option>
<option value="I" <?php if($data['brg'] == 'I'){ echo 'selected'; } ?> >I</option>
<option value="E" <?php if($data['brg'] == 'E'){ echo 'selected'; } ?> >E</option>
<option value="C" <?php if($data['brg'] == 'C'){ echo 'selected'; } ?> >C</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Tipe</label>
<div class="col-md-2 col-sm-2 col-xs-12">
<select name="jalur" class="select2_single form-control" tabindex="-1">
<option value="">Jalur...</option>
<option value="HL" <?php if($data['jalur'] == 'HL'){ echo 'selected'; } ?> >HL</option>
<option value="HM" <?php if($data['jalur'] == 'HM'){ echo 'selected'; } ?> >HM</option>
<option value="HH" <?php if($data['jalur'] == 'HH'){ echo 'selected'; } ?> >HH</option>
<option value="KL" <?php if($data['jalur'] == 'KL'){ echo 'selected'; } ?> >KL</option>
<option value="KM" <?php if($data['jalur'] == 'KM'){ echo 'selected'; } ?> >KM</option>
<option value="KH" <?php if($data['jalur'] == 'KH'){ echo 'selected'; } ?> >KH</option>
<option value="ML" <?php if($data['jalur'] == 'ML'){ echo 'selected'; } ?> >ML</option>
<option value="MM" <?php if($data['jalur'] == 'MM'){ echo 'selected'; } ?> >MM</option>
<option value="MH" <?php if($data['jalur'] == 'MH'){ echo 'selected'; } ?> >MH</option>
<option value="MK" <?php if($data['jalur'] == 'MK'){ echo 'selected'; } ?> >MK</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" >No doc</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="no_dok" value="<?php echo $data['no_dok']?>" class="form-control">
</div>
<div class="col-md-3 col-sm-3 col-xs-12">
<input id="tglx1" name="tgl_dok" class="date-picker form-control has-feedback-left" type="text" value="<?php echo $data['tgl_dok']?>">
<span class="fa fa-calendar-o form-control-feedback left" aria-hidden="true"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" >No Surat</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="no_print" value="<?php echo $data['no_print']?>" class="form-control">
</div>
<div class="col-md-3 col-sm-3 col-xs-12">
<input id="tglx2" name="tgl_print" class="date-picker form-control has-feedback-left" type="text" value="<?php echo $data['tgl_print']?>">
<span class="fa fa-calendar-o form-control-feedback left" aria-hidden="true"></span>
</div>
</div>
<!--ssssssss-->
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
<?php } ?>
这是更新代码
<?php
include 'conn.php';
$id=$_POST['id'];
$nama_pt=$_POST['nama_pt'];
$brg=$_POST['brg'];
$jalur=$_POST['jalur'];
$no_dok=$_POST['no_dok'];
$tgl_dok=$_POST['tgl_dok'];
$no_print=$_POST['no_print'];
$tgl_print=$_POST['tgl_print'];
mysqli_query($terhubung, "UPDATE data222 SET
id='$id',
nama_pt='$nama_pt',
brg='$brg',
jalur='$jalur',
no_dok='$no_dok',
tgl_dok='$tgl_dok',
no_print='$no_print',
tgl_print='$tgl_print',
WHERE id ='$id'
");
?>
当我点击提交时,mysql没有变化。什么是错误
答案 0 :(得分:0)
尝试是否可以改变这个
<button type="submit" class="btn btn-success">Submit</button>
到
<input type="submit" name="update" class="btn btn-success" />
并更改更新代码
<?php
if (isset($_POST['update'])){
copy paste the code you write in update
}
答案 1 :(得分:0)
尝试使用查询
在{}
中编辑置位变量