Click here to Skip to main content
13,093,097 members (64,455 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 3:20am
Updated 1-May-13 5:00am
"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 = '<php echo="">'>
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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2017
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