submit button on each update row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daheffley
Forum Newbie
Posts: 2
Joined: Fri Mar 04, 2011 6:32 pm

submit button on each update row

Post by daheffley »

I have a form that is posts back to itself and in the form I show a list of data from mysql and at the end of each row in the list is a submit button.
What I need is for when the user clicks on the submit button it updates the database based on the value of one of 3 radio buttons that are also on the form. I retrieve the data fine and displays fine in the form, I'm having problems capturing the correct rowid when I click on the submit button, I need to be able to update the correct id when I click on submit and it should perform something, that I have coded below.

What it does now is I get the first promocode_id only regardless of any submit button I click.

What am I doing wrong if anyone can help much appreciated!


<?php
require_once('Connections/pbData.php');

mysql_select_db($database_pbData,$pbData);

if(isset($_POST['actsubmit']) && $_POST['actsubmit'] != ""){
if(isset($_POST['activate'])){
if ($_POST['activate'] == 'sactivate') {
echo $_POST['rowid'][$i]; testing the output of the ID
//$standactivate1 = 1;
$qry = "UPDATE ftc_promocode SET promoCodeStandActivate =1 WHERE promocode_id='".$_POST['rowid'][$i]."'";
$result2 = @mysql_query($qry);
}
else if ($_POST['activate'] == 'mactivate') {
echo "nope";
//$membactivate1 = 1;
$qry = "UPDATE ftc_promocode SET promoCodeMembActivate =1 WHERE promocode_id='".$_POST['rowid'][$i]."'";
$result2 = @mysql_query($qry);
}
else if ($_POST['activate'] == 'deactivate') {
echo "oh no!";
//$deactivate1 = 0;
$qry = "UPDATE ftc_promocode SET promoCodeStandActivate =0, promoCodeMembActivate =0 WHERE promocode_id='".$_POST['rowid'][$i]."'";
$result2 = @mysql_query($qry);
}
}
}
?>

some html here
<?php
$SQL = "SELECT * FROM table";
$result1 = mysql_query($SQL);

$num = mysql_num_rows($result1);

$i = 0;

while($row=mysql_fetch_array($result1)){

?>
<tr>
<td><?php echo $row['id']; ?>
</td>
<td><?php echo $row['promocode_id']; ?>
</td>
<td><?php echo $row['promoCode']; ?>
</td>
<td><?php echo $row['promoCodeStandActivate']; ?>
</td>
<td><?php echo $row['promoCodeMembActivate']; ?>
</td>
<td><input type="radio" name="activate" value="sactivate" />
</td>
<td><input type="radio" name="activate" value="mactivate" />
</td>
<td><input type="radio" name="activate" value="deactivate" />
</td>
<td><input type="submit" name="actsubmit" value="Submit" />
</td><input type="hidden" name="rowid" value="<?php echo $row['id']; ?>" />
</tr><?php $i++; } ?>
</table>
</form>
daheffley
Forum Newbie
Posts: 2
Joined: Fri Mar 04, 2011 6:32 pm

Re: submit button on each update row

Post by daheffley »

Found the answer on this board and I apologize for asking before browsing.

I decided to give the submit button the value of the rowid and that worked.

Thank you!
Post Reply