Search code examples
phpbuttonsend

Send column name from button


I have made a php page. On which I am displaying table 'prod' from my data base. each row is displayed nicely. Today i tried to add a button named 'rate' at the end of each row of my table. which I did successfully. Now I want to send the the value of the first column of that row to another php page when that button is clicked. I am stuck that how to do so? can you help please ??

I know i have to use the method post in my form and i have to use $_post[that value] on the other php page to inculcate the value for further function.

I just need to ask that where to add the value of my first column in the button line. so that onclick it can send that value. I hope I am clear over this. Thank You very much for help :)

<?php 
include("connection.php");

$query = "select *  from prod"; 
$res = oci_parse($conn,$query); 
usleep(100); 
if (oci_execute($res)){ 
        usleep(100); 
       
   print "<TABLE border \"1\">"; 
        $first = 0; 
        while ($row = @oci_fetch_assoc($res)){ 
                if (!$first){ 
                        $first = 1; 
                        print "<TR><TH>"; 
                        print implode("</TH><TH>",array_keys($row)); 
                        print "</TH></TR>\n"; 
                } 
                print "<TR><TD>"; 
                print @implode("</TD><TD>",array_values($row)); 
                print "</TD></TR>\n"; 
				
            echo "<td><form action='detailform.php' method='POST'><input type='submit' name='submit-btn' value='Rate'/></form></td></tr>";
		   
		}     
        print "</TABLE>"; 

		} 
	
?>


Solution

  • you have to add inputs in your form whatever kind u prefer

    echo "<td>
              <form action='detailform.php' method='POST'>
                   <input type='hidden' name='your_val_key' value='".$row[your_val_key_in_query]."'> <!-- input hidden, change to text 4 debug -->
                   <input type='submit' name='submit-btn' value='Rate'/>
              </form>
          </td></tr>";
    

    and than, in your detailform.php u can get the val with

    echo $_POST["your_val_key"];
    

    if u are not sure how much data u send or somthing, try this and u get the full data:

    echo "<pre>".print_r($_POST,true)."</pre>";
    

    BTW: why are u mixing print and echo?