Mutliple Submit buttons

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
A7x
Forum Newbie
Posts: 10
Joined: Thu Mar 03, 2011 6:07 am

Mutliple Submit buttons

Post 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! (:
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Mutliple Submit buttons

Post 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>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
A7x
Forum Newbie
Posts: 10
Joined: Thu Mar 03, 2011 6:07 am

Re: Mutliple Submit buttons

Post 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... :)
Post Reply