0

I have a error problem with my code in php. can anyone help me to correct it!

<?php $query_tbl = "SELECT transaksi.id_transaksi, pelanggan.nama FROM transaksi, pelanggan ". 
            "WHERE transaksi.id_pelanggan = pelanggan.id_pelanggan ORDER BY id_transaksi";

        $list_tbl = mysqli_query($dbc, $query_tbl)
            or die('Error select table');

        while($row = mysqli_fetch_array($list_tbl))
        { 
            echo '<tr>';
            echo '<td>' . $row['id_transaksi'] . '</td>';
            echo '<td>' . $row['nama'] . '</td>';
            <form method="post" action="pengiriman-input.php">
                <input type="hidden" name="id" value="<?php echo $row['id_transaksi']; ?>" />
                <input type="submit" value="Kirim" />
            </form>
            echo '</tr>';
        };?>

In Chrome i get this notif:

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\delivery\pengiriman.php on line 33.

I don't know what is wrong because i am new with php.

And btw line 33 is

<form method="post" action="pengiriman-input.php">
Raptor
  • 53,206
  • 45
  • 230
  • 366
Mahfud Muhammad
  • 169
  • 1
  • 11

5 Answers5

1

there is some syntex error while putting HTML between PHP near your form tag

<?php $query_tbl = "SELECT `transaksi.id_transaksi`, `pelanggan.nama` FROM `transaksi`, `pelanggan` WHERE 
`transaksi.id_pelanggan` = `pelanggan.id_pelanggan` ORDER BY `id_transaksi`";

        $list_tbl = mysqli_query($dbc, $query_tbl)
            or die('Error select table');

        while($row = mysqli_fetch_array($list_tbl))
        { 
            echo '<tr>';
            echo '<td>' . $row['id_transaksi'] . '</td>';
            echo '<td>' . $row['nama'] . '</td>';?>
            <form method="post" action="pengiriman-input.php">
                <input type="hidden" name="id" value="<?php echo $row['id_transaksi']; ?>" />
                <input type="submit" value="Kirim" />
            </form>
          <?php   echo '</tr>';
        };?>
Vivek Singh
  • 2,453
  • 1
  • 14
  • 27
1

Try this more simple and neat code

<?php
    $query_tbl = "SELECT transaksi.id_transaksi, pelanggan.nama FROM transaksi, pelanggan ". "WHERE transaksi.id_pelanggan = pelanggan.id_pelanggan ORDER BY id_transaksi";
    $list_tbl = mysqli_query($dbc, $query_tbl) or die('Error select table');
?>


<?php while($row = mysqli_fetch_array($list_tbl)): ?>
    <tr>
        <td><?php echo $row['id_transaksi']; ?></td>
        <td><?php echo $row['nama']; ?></td>
        <td>
            <form method="post" action="pengiriman-input.php">
                <input type="hidden" name="id" value="<?php echo $row['id_transaksi']; ?>" />
                <input type="submit" value="Kirim" />
            </form>
        </td>
    </tr>
<?php endwhile; ?>
Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
  • Can you use the `while():` - `endwhile;` syntax in vanilla PHP? Or is that only when you use an template engine? – Mathlight May 11 '15 at 07:29
  • i try this. and it works. but the button is placed above the table. – Mahfud Muhammad May 11 '15 at 07:29
  • @MahfudMuhammad, that's because It's not in the `td` tags. Put it between them, and You should be fine – Mathlight May 11 '15 at 07:30
  • oh yeah! it works. thanks. but i one question now. the table is border='1', so the make the button arounded by line. can the line around the button removed? – Mahfud Muhammad May 11 '15 at 07:37
  • @MahfudMuhammad yes. For that you can remove the `border='1'` part, or [Fiddle around with the CSS Border](http://www.w3schools.com/css/css_border.asp) – Mathlight May 11 '15 at 07:41
  • @Mathlight i already removed it `border="1"` but the line still there. – Mahfud Muhammad May 11 '15 at 07:56
  • @MahfudMuhammad then you have to take a look at the [Chrome DevTools](https://developer.chrome.com/devtools) and see what is creating the border and delete / override that part of the code – Mathlight May 11 '15 at 08:12
  • @MahfudMuhammad Hi, you can add the form inside should be ok after that. about the line around the button, maybe you should check the css, check this http://stackoverflow.com/questions/3397113/how-to-remove-border-outline-around-text-input-boxes-chrome – Josua Marcel C May 11 '15 at 08:36
  • @Mathlight ofcourse can do that on all .php file extension – Josua Marcel C May 11 '15 at 08:39
0

You can't put HTML directly into PHP

<?php $query_tbl = "SELECT transaksi.id_transaksi, pelanggan.nama FROM transaksi, pelanggan ". 
        "WHERE transaksi.id_pelanggan = pelanggan.id_pelanggan ORDER BY id_transaksi";

    $list_tbl = mysqli_query($dbc, $query_tbl)
        or die('Error select table');

    while($row = mysqli_fetch_array($list_tbl))
    { 
        echo '<tr>';
        echo '<td>' . $row['id_transaksi'] . '</td>';
        echo '<td>' . $row['nama'] . '</td>';
?>  <!-- here ends the PHP -->
        <form method="post" action="pengiriman-input.php">
            <input type="hidden" name="id" value="<?php echo $row['id_transaksi']; ?>" />
            <input type="submit" value="Kirim" />
        </form>
<?php // here begin PHP again
        echo '</tr>';
    };?>
pavel
  • 26,538
  • 10
  • 45
  • 61
0

You need to end the php then start it again. Try this:

<?php $query_tbl = "SELECT transaksi.id_transaksi, pelanggan.nama FROM transaksi, pelanggan ". 
            "WHERE transaksi.id_pelanggan = pelanggan.id_pelanggan ORDER BY id_transaksi";

    $list_tbl = mysqli_query($dbc, $query_tbl)
        or die('Error select table');

    while($row = mysqli_fetch_array($list_tbl))
    { 
        echo '<tr>';
        echo '<td>' . $row['id_transaksi'] . '</td>';
        echo '<td>' . $row['nama'] . '</td>';
        ?>
        <form method="post" action="pengiriman-input.php">
            <input type="hidden" name="id" value="<?php echo $row['id_transaksi']; ?>" />
            <input type="submit" value="Kirim" />
        </form>
    <?php
        echo '</tr>';
    };?>
0

In the above snippet you are opening a php tag in line 1 and have thought of closing it at last line. Between these two tag you cannot write the html script for creating form, as you are doing, in a php file.

It will be taken as a php script instead of html script and php compiler don't understands html tags.

Create the form tag as a php string variable and echo it as you are doing in the lines above.

Luke P. Issac
  • 1,471
  • 15
  • 32