Click here to Skip to main content
Rate this: bad
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>
         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
Edited 1-May-13 6:00am
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...
Rate this: bad
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">
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:[^],
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.
Rate this: bad
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.
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 OriginalGriff 345
1 DamithSL 140
2 Zoltán Zörgő 120
3 Afzaal Ahmad Zeeshan 105
4 Sergey Alexandrovich Kryukov 99
0 enhzflep 40
1 Richard Deeming 25
2 OriginalGriff 10
3 Anddos 10
4 Kornfeld Eliyahu Peter 10

Advertise | Privacy | Mobile
Web04 | 2.8.150224.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2015
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