Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP MySQL
Someone help here. Am trying to change the name of Buttons dynamically in PHP but it aint working i.e while
($row= mysqli_fetch_array($r, MYSQLI_ASSOC))
    {
        $Inventory_Name = $row['Inventory_Name'];
        $Inventory_ID = $row['Inventory_ID'];
 
        echo "<td bgcolor = 'grey'> ".$Inventory_Name."</td> ";
       <td bgcolor = 'grey'> &lt;input type = 'button' value = 'Edit' name = '<?php echo $Inventory_ID;?>'> </td> </tr>
         <?php
         echo "&lt;/form> ";
         
 
        }
    }
$inventory_query = "SELECT * FROM inventory WHERE Inventory_ID = $_POST[$Inventory_ID]";
I cant pass the value of $_POST[$Inventory_ID] when i click the buttons
Posted 1-May-13 4:20am
Jamkom273
Edited 1-May-13 6:00am
v4
Comments
Sergey Alexandrovich Kryukov at 1-May-13 10:42am
   
"Not working" is not informative. What HTML is generated, instead what you wanted? Everything is created "dynamically" anyway...
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You code cannot post anything because it looks like a complete gibberish. If has a closing "form" tag, but not opening.
 
You need to generate the form like in this minimalistic example:
<form name="form" action="some_uri" method="post" enctype="multipart/form-data">
Name: <input type="text" name="name"><br/>
<!-- ... -->
<input type="submit" value="Submit">
</form>
 
Important detail: "name" attributes are important to use on the server side ("some_uri" will be loaded), multipart enctype is important if you mix MIME types (learn other types, please see the link below), say file input with text, one of the buttons should be "submit".
 
Please see, learn other options: http://www.w3schools.com/tags/tag_form.asp[^],
 
Load your PHP page and look at the generated HTML in the browser (something like "View" / "Page Source"), and check up that the HTML looks right, only then continue with server part.
 
—SA
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thanks @Sergey Alexandrovich Kryukov. I know how to handle forms but my problem was with
<!-- <input type = 'button' value = 'Edit' name = ''>
I want buttons to be created in the WHILE LOOP and the NAME property of each button to change accordingly. I cant paste the whole code here bse its long. Hope i've tried to make it a bit clear. Basically i want someone to click the button and he is able to capture the value of $_POST['$Inventory_ID'] to be used in another query.
  Permalink  
v4
Comments
richcb at 1-May-13 11:52am
   
Use the "Have a Question or Comment?" or "Improve question" widget to ask a question or post a comment. You posted a question as a solution to your own question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Mathew Soji 335
2 BillWoodruff 260
3 OriginalGriff 215
4 Afzaal Ahmad Zeeshan 188
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100