1

How do i get the row id?

I'm doing a site of music, i need do the admin page,this part is when the admin gonna edit the albums. I need the id to specify what music gonna change the informations.

      <?php
$db = mysqli_connect("localhost", "root", "", "datamusic");
$result = mysqli_query($db, "SELECT * FROM musics");
    while ($row = mysqli_fetch_array($result)) {
        echo "<div id='img_div'>";
        echo "<img src='images/" . $row['Image'] . "' >";
        echo "<p>" . $row['Band/Singer'] . "</p>";
        echo "<form method='POST' action='editInformations.php'><p name=" . $row['id'] . ">ID = " . $row['id'] . "</p></form>";
        echo "<a href='editInformations.php'><button type='submit'>Editar</button></a>";
        echo "</div>";

    }

    ?>

I try something like that, but doesn't works

//editInformations.php

$id =$_POST[$row['id']];
echo $id;
Yem
  • 33
  • 3
  • What do you get from a `var_dump()` or `print_r()` of `$_POST`? Maybe this will help - https://stackoverflow.com/questions/9332718/how-do-i-print-all-post-results-when-a-form-is-submitted – DaveStSomeWhere Mar 10 '18 at 16:05

1 Answers1

0

Get edit page GET funciton. You can put id for edit.

editInformations.php?id=".$row['id']."

Change code with this.

<?php
$db = mysqli_connect("localhost", "root", "", "datamusic");
$result = mysqli_query($db, "SELECT * FROM musics");
    while ($row = mysqli_fetch_array($result)) {
        echo "<div id='img_div'>";
        echo "<img src='images/" . $row['Image'] . "' >";
        echo "<p>" . $row['Band/Singer'] . "</p>";
        echo "<form method='POST' action='editInformations.php'><p name=" . $row['id'] . ">ID = " . $row['id'] . "</p></form>";
        echo "<a href='editInformations.php?id=".$row['id']."'><button type='submit'>Editar</button></a>";
        echo "</div>";

    }

    ?>

//editInformations.php

$id =$_GET['id'];
echo $id;