I wonder why it doesn't want to retrieve the P_id information when I press hapus/delete button. It suppose to bypass P_id value so that I know which to delete.

The url remains empty: http://localhost/innovation/script_shop/hapus.php?P_id=

<?php

    $result = mysql_query("SELECT * FROM stock")
    or die(mysql_error());

    echo "<table border=1>";
    echo "<tr>";
    echo "<th>Produk</th><th>Jumlah</th><th>Tanggal</th>";
    echo "</tr>";


    $i=0;
    while($row = mysql_fetch_array( $result )) {    
    $result2=($i%2)?'#DFA09D':'white';

    echo "<tr bgcolor='$result2'>";
    echo "<td>";
    echo $row['Produk'];
    echo "</td>";
    echo "<td>";
    echo $row['Jumlah'].'<br/>';
    echo "</td>";
    echo "<td>";
    echo $row['Tanggal'];
    echo "</td>";
    echo "<td>";
    echo "Edit";
    echo "</td>";
    echo "<td>";
    echo "<a href='hapus.php?P_id='".$row['P_id'].">hapus</a>";
    echo "</td>";
    echo "</tr>";

    $i++;
    } 
Member Avatar for LastMitch

@davy_yg

I wonder why it doesn't want to retrieve the P_id information when I press hapus/delete button. It suppose to bypass P_id value so that I know which to delete.

What are you talking?

I don't see any function that you are trying to retrieve from the database nor a button that delete a valve.

All I see is 2 query. One is to SELECT and the other to Fetch an ID.

You didn't how it works or how it bypass a valve.

Are you sure that the column in the database is called P_id?

hapus means delete. Yes, there is column in the database called P_id it's primary key and auto increment. P_id means product id.

If that is definitely the correct column name then your formatting is incorrect for the echo and you are missing a ' befoe the closing > of the href.

I always find it best / easiest to keep HTML and PHP separate so can you try this and see if it works

while($row = mysql_fetch_array( $result )) {    
    $result2=($i%2)?'#DFA09D':'white';
}
    <tr bgcolor="<?php echo $result2; ?>";
    <td><?php echo $row['Produk']; ?></td>
    <td><?php echo $row['Jumlah']; ?></td>
    <td><?php echo $row['Tanggal']; ?></td>
    <td>Edit</td>
    <td><a href="hapus.php?P_id=<?php echo $row['P_id']; ?>">hapus</a></td>
    </tr>
<?php
    $i++;
?>

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\Innovation\script_shop\stock3.php on line 102

line 102:<tr bgcolor="<?php echo $result2; ?>">

Sorry to be rude, but surely you can work out that there is a missing closing tag and don't need help with that???

I made a typo:

<tr bgcolor="<?php echo $result2; ?>">
commented: You're not rude. You'll absolute right! +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.