Jump to content

Submit button in while-loop


stirrah

Recommended Posts

Hey!

 

How should I do if I want to populate a table with results from DB, and then make a submit button beside each row..and then make a query depending on the values of that row.

 

This is my code right now:

if (isset($_POST['submit'])){
  // do some query to the db depending on row
}



	?>
      <h2>Accept or decline your invitation:</h2>
      <?php 
$my_id = $user_data['user_id'];
$query = mysql_query(MY QUERY) ?>

     <table class='display'>
             <th>ID</th>
              
              <th>Namn</th>
              <th>Inbjuden av</th>
              <th>Svara</th>
              <?php
                  while($row = mysql_fetch_assoc($query)) 
                  { ?>
		    <tr>
        <td><?php echo "<a href='project.php?pid=" . $row['projectId'] . "'>" . $row['projectId'] . "</a>"; ?></td> 
		    <td><?php echo $row['projektName'] ?></td>
        <td><?php echo $row['username'] ?></td>
        <td><form action="" method="POST"><input type="submit" name="submit" value="Accept!"></form></td>
		    </tr>
		
<?php } ?>

Problem with this setup is that it will submit all the rows before aswell..

Link to comment
Share on other sites

To accept a specific database entry, the form needs to be updated to pass that entry's ID. If you want to stick with HTML forms, you could add the ID to a hidden field. If you're not familiar with creating hidden fields, perhaps the following will help:

http://www.tizag.com/htmlT/htmlhidden.php

 

 

Note that you could also use an HTML link. For example, you could try something like this:

<td><?php echo "<a href='?accept=" . $row['projectId'] . "'>Accept</a>"; ?></td>

Just keep in mind that the information passed through links are GET variables. So you would need to use $_GET.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.