Jump to content


Having trouble using $_POST[]

  • Please log in to reply
2 replies to this topic

#1 CMellor

  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationLeeds, UK

Posted 25 April 2006 - 04:28 PM

First, I'd like to show my code:

<form action="" method="post">
    <table width="100%" cellspacing="0" cellpadding="0">
        <td width="30%" align="center" class="header">Team Name</td>
        <td width="40%" align="center" class="header">Members</td>
        <td width="20$" align="center" class="header">Accept</td>
        <td width="10%" align="center" class="header">Delete</td>
      <?php $query = mysql_query("SELECT * FROM $dbname.request_stable");
      while($row = mysql_fetch_array($query)) {
        if($_GET['accept'] == "true") {
          mysql_query("UPDATE $dbname.request_stable SET accepted = 'yes' WHERE id = ".$_POST['id']."");
        <td class="row2"><?=$row['group_name']?></td>
        <td class="row2"><strong><?=$row['leader']?></strong><br /><?=$row['members']?></td>
        <td align="center" class="row2"><input type="hidden" name="id" value="<?=$row['id']?>" />
        <?php if($row['accepted'] == "no") { ?>Not Appepted<br />
                [ <a href="?do=interactive_requests_stable&accept=true">Accept</a> ]
        <?php } else { ?>Accepted<?php } ?>
        <td align="center" class="row2"><input type="checkbox" name="delete[]" value="<?=$row['id']?>" /></td>
      <?php } ?>
    <div align="right">
        <input type="submit" name="delete_stable" value="Delete Selected" class="button" /></div>

That produces a table that grabs some details from the DB. In the DB, their is a table called 'accepted' and can have the value of 'yes' or 'no'. When set to 'no', it says Not Accepted [ Accept ] and when set to 'yes' it says Accepted.

I want it so when you click [ Accept ], it updates the DB status to 'yes' from 'no'. I thought putting a hidden input with the row id as the value, then using $_POST['id'] in the mysql query might get it to set the selected row to update, but nothing happens when I click it.

Hope I make sense, I never seem to think I do when I ask for help here.

Thanks for taking the time to look and I hope to hear from you soon.


#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 April 2006 - 05:08 PM

The reason why it aint working is becuase you are using a link and so the form isn't being submitted and so no $_POST array is created. What you will want to is put id into the link like so:
<a href="?do=interactive_requests_stable&accept=true&id=<?=$row['id']?>">Accept</a>
Then change $_POSt['id'] in your SQL Quuery to $_GET['id'] so you SQL Query will be like so:
mysql_query("UPDATE $dbname.request_stable SET accepted = 'yes' WHERE id = ".$_GET['id']."");

#3 CMellor

  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationLeeds, UK

Posted 25 April 2006 - 05:34 PM

Cheers bud. Believe it or not, I actually figured it out after I posted this, lol, but I did it pretty much the way you suggested.

Thanks again.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users