0

So i want to place this code below

 $keyword="";
    if (isset($_POST['searchpakaian'])) {
        $keyword = $_POST['searchpakaian'];
    }

    $query = mysqli_query($conn,"SELECT * FROM tbl_pakaian WHERE nama_pakaian LIKE '%".$keyword."%' ORDER BY id ASC limit 0,6");
    $hitung_data = mysqli_num_rows($query);
    if ($hitung_data > 0) {
    while ($row = mysqli_fetch_array($query)) { 
    ?>
    
    <div class="col">
        <div class="card h-100">
            <div class="card-img-wrap ">
                <img src="img/Galeri/pakaian/<?php echo $row['gambar_pakaian'] ?>" class="card-img-top" alt="...">
            </div>
            <div class="card-body">
                <h5 class="card-title"><?php echo $row['nama_pakaian'] ?></h5>
                <p class="card-text "><?php echo $row['keterangan_pakaian'] ?></p>
            </div>
        </div>
    </div>

<?php } } else { ?> 
    <center><h4>Tidak Ada Data</h4></center>
<?php } ?>

On if conditional statement

if($req == 'something'){

}

Here is my full code

<?php
    include '../koneksi.php';
    $req = $_REQUEST['req'];
    $keyword="";
    if (isset($_POST['searchpakaian'])) {
        $keyword = $_POST['searchpakaian'];
    }

    $query = mysqli_query($conn,"SELECT * FROM tbl_pakaian WHERE nama_pakaian LIKE '%".$keyword."%' ORDER BY id ASC limit 0,6");
    $hitung_data = mysqli_num_rows($query);
    if ($hitung_data > 0) {
    while ($row = mysqli_fetch_array($query)) { 
    ?>
    
    <div class="col">
        <div class="card h-100">
            <div class="card-img-wrap ">
                <img src="img/Galeri/pakaian/<?php echo $row['gambar_pakaian'] ?>" class="card-img-top" alt="...">
            </div>
            <div class="card-body">
                <h5 class="card-title"><?php echo $row['nama_pakaian'] ?></h5>
                <p class="card-text "><?php echo $row['keterangan_pakaian'] ?></p>
            </div>
        </div>
    </div>

<?php } } else { ?> 
    <center><h4>Tidak Ada Data</h4></center>
<?php } ?>

If i just copy the code to the if conditional statement code, it just say 'unexpected end of file'

What should i do?

Mas Hehy
  • 11
  • 1
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman Jun 25 '22 at 10:10

1 Answers1

1

The syntax error are vey simple to find just confirm that when you copy inside the if, dont repeat php keys as and the echo finish it with ;

<?php echo('hello world'); ?>

OR the same echo but simple deleting the php tag by = simbol (only work with echo)

<?= 'hello world' ?>
hejevero
  • 11
  • 3