It seems that my code is wrong. I'm using method GET and pass the variable on its page. This is my form code.
看来我的代码错了。我正在使用方法GET并在其页面上传递变量。这是我的表单代码。
<form method="get" action="?nama'">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-search"></i></span>
<input type="text" class="form-control" name="nama" placeholder="Cari berdasarkan Nama Lengkap Pendaftar" aria-describedby="basic-addon1">
<span class="input-group-btn">
<button class="btn btn-success" type="submit">Go!</button>
</span>
</div>
</form>
And this is for the GET method. I'm using table to write the result.
这是针对GET方法的。我正在使用表来写结果。
<div class="table-responsive">
<table class="table table-bordered table-hover">
<tr style="font-weight: bold; text-align: center;">
<td> No. </td>
<td> ID Pendaftaran </td>
<td> Nama Lengkap </td>
<td> Jenis Kelamin </td>
<td> Asal Sekolah </td>
<td> Tanggal Daftar </td>
<td> Pengembalian Form </td>
</tr>
<?php
if (isset($_GET['nama'])) {
$no = 1;
$nama = $_GET['nama'];
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."'%'");
while ($loop = mysqli_fetch_array($query)) {
?>
<tr style="text-align: center;">
<td> <?php echo $no; ?> </td>
<td> <?php echo $loop['IDPENDAFTAR']; ?> </td>
<td> <?php echo $loop['NAMAPENDAFTAR']; ?> </td>
<td> <?php echo $loop['JENISKELAMIN']; ?> </td>
<td><?php echo $loop['SEKOLAHASAL']; ?> </td>
<td><?php echo date('d-m-Y', strtotime($loop['TANGGALDAFTAR'])); ?> </td>
<td><button type="button" name="kembali" class="btn btn-default" data-toggle="modal" data-target="#myModal">Form Kembali</button></td>
</tr>
<?php
$no++;
}
}
else {
$no = 1;
$query1 = mysqli_query($koneksi, "SELECT * FROM pendaftar");
while ($loop = mysqli_fetch_array($query1)) {
?>
<tr style="text-align: center;">
<td> <?php echo $no; ?> </td>
<td> <?php echo $loop['IDPENDAFTAR']; ?> </td>
<td> <?php echo $loop['NAMAPENDAFTAR']; ?> </td>
<td> <?php echo $loop['JENISKELAMIN']; ?> </td>
<td><?php echo $loop['SEKOLAHASAL']; ?> </td>
<td><?php echo date('d-m-Y', strtotime($loop['TANGGALDAFTAR'])); ?> </td>
<td><button type="button" name="kembali" class="btn btn-default" data-toggle="modal" data-target="#myModal">Form Kembali</button></td>
</tr>
<?php
$no++;
}
}
?>
</table>
</div>
It gets error like this.
它会像这样出错。
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\WebKP\admin-site.php on line 126 But while I'm trying to query on my phpmyadmin, it has the results.
警告:mysqli_fetch_array()期望参数1为mysqli_result,第126行的C:\ xampp \ htdocs \ WebKP \ admin-site.php中给出布尔值但是当我尝试查询我的phpmyadmin时,它有结果。
1 个解决方案
#1
1
You have SQL syntax error here
这里有SQL语法错误
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."'%'");
Use below code
使用下面的代码
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."%'")
#1
1
You have SQL syntax error here
这里有SQL语法错误
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."'%'");
Use below code
使用下面的代码
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."%'")