Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error when trying to get the button id using PHP

I am generating a list of buttons with the id being a value extracted from a database. Then I want to take this id and display. But, when I try to do that, I get an error. Can some one tell me what I’m doing wrong here.

Button generation

 //This function will display items  
 function showItems($sqlString)
 {
    $result = mysqli_query($this->connectToDb(), $sqlString);
    //var_dump($result);
    if(mysqli_num_rows($result) > 0)
    {           
        foreach ($result as $row) 
        {                 
            echo "<div class='div_item'>";
            echo  "<img src='../images/uploads/".$row['It_image']."' style='width:200px;height:150px;'>"."<br>";
            echo  "IT CODE: ".$row['It_code']."<br>"; 
            echo  "ITEM: ".$row['It_name']."<br>"; 
            echo  "DESC: ".$row['It_desc']."<br>"; 
            echo  "QTY AVAIL: ".$row['qty']."<br>"; 
            echo  "PRICE: ".$row['price']."<br>";
                echo "<form enctype='multipart/form-data' action='' method='POST'>";
                echo  "<button type='submit' name='id' id='".$row['It_code']."'>Buy</button>";
                echo  "</form>";
            echo  "</div>";
        }
   }
}

Displaying the ID when the respective button is clicked

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  //get id of the button
  if (isset($_POST['id']))
  {
    echo $_GET['id'];
  }

Error

enter image description here

>Solution :

Pass it inside value value=’".$row[‘It_code’]."’

 echo  "<button type='submit' value='".$row['It_code']."' name='id' id='".$row['It_code']."'>Buy</button>";

           
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading