Page 1 of 1

Mutliple Submit buttons

Posted: Sun Mar 06, 2011 2:15 am
by A7x
Hey there! I'm kinda new to PHP and so I have one question... I am curretnly working on admin dashboard for my website where I can pay users for they "work" (i think it's not important what it is for now)... Now I've used this script to get all of the data from the database "payrequest" in a table:
<?php
mysql_connect("localhost","root","root");
mysql_select_db("mydb");
$result = mysql_query("SELECT * FROM payrequest");
{
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Requested by</th>
<th>Amount</th>
<th>Status</th>
</tr>
";
}
while ($row1 = mysql_fetch_array($result))
{
$submit = "<form action='admin_payments.php' method='post'>
<input type='submit' name='pay' value='Pay'>
</form>";
echo "<tr>";
echo "<td>".$row1['id']."</td>";
echo "<td>".$row1['requestby']."</td>";
echo "<td>".$row1['amount']." $</td>";
echo "<td>";
include('pay.php'); //include Pay button for every record
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
it looks like this:
Image

Inside 'pay.php' is a single submit button and form action, this script goes like:
<form action='admin_pay_function.php' method='post'>
<input type='submit' name='pay' value='Pay'>
</form>
and inside admin_pay_function.php is
<?php
session_start();
$user = $_SESSION['username'];
$pay = $_POST['pay'];
if ($user)
{
mysql_connect("localhost","root","root") or die ("DB connexion failed");
mysql_select_db("mydb") or die ("couldnt select db");
mysql_query("UPDATE payrequest SET status='Paid'");
}
?>
but the problem is, that this script will update all users status 'Paid' and I want to update it just there, where I pressed the "Pay" button and I have no idea how to make it work ... Thank you! (:

Re: Mutliple Submit buttons

Posted: Sun Mar 06, 2011 4:47 am
by social_experiment
In your 'pay.php' form you can put a hidden field that contains a value unique to each record, one of the following perhaps

Code: Select all

echo "<td>".$row1['id']."</td>";
echo "<td>".$row1['requestby']."</td>";
echo "<td>".$row1['amount']." $</td>";
// your form would be modified like this
<form action='admin_pay_function.php' method='post'>
<input type="hidden" name="uniqueId" value="' . $row['id'] . '" />
<input type='submit' name='pay' value='Pay'>
</form>

Re: Mutliple Submit buttons

Posted: Mon Mar 07, 2011 2:55 pm
by A7x
social_experiment wrote:In your 'pay.php' form you can put a hidden field that contains a value unique to each record, one of the following perhaps

Code: Select all

echo "<td>".$row1['id']."</td>";
echo "<td>".$row1['requestby']."</td>";
echo "<td>".$row1['amount']." $</td>";
// your form would be modified like this
<form action='admin_pay_function.php' method='post'>
<input type="hidden" name="uniqueId" value="' . $row['id'] . '" />
<input type='submit' name='pay' value='Pay'>
</form>
man... i'm not a gay but I LOVE YOU.. thank you :D it solved my problem... :)