1

im making some application form in PHP.

im putting all info returned from the database into a table.

Now i want to create a button on each line that changes something in the DB of that line.

but i have no idea to do that :S

Thank you!

echo "<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>age</th>
<th>position</th>
<th>experience</th>
<th>motivation</th>
<th>date</th>
<th>status</th>
<th>test</th>
</tr>";

while($row = mysql_fetch_array($result))
    {
        echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "<td>" . $row['age'] . "</td>";
    echo "<td>" . $row['position'] . "</td>";
    echo "<td>" . $row['exp'] . "</td>";
    echo "<td>" . $row['motivation'] . "</td>";
    echo "<td>" . $row['date'] . "</td>";
    echo "<td>" . $row['status'] . "</td>";
    echo "<td>" . '<input type="submit" name="submit" value="accept">' . "</td>";
    echo "</tr>";

}
    echo "</table>";

EDIT: get it working using another script:

echo "<td><a href=\"edit.php?id=".$row['id']."&status=app\">Approve</a></td>";

and edit.php:

<?php
include("dbconnect.php");
$member_id = $_GET['id'];
$status = $_GET['status'];
echo $member_id;
echo $status;
if ($status == 'app')
    $query = "update apps set status = 'approved' where id = $member_id";
mysql_query($query) or die (mysql_error());  
?>
12
  • Which part are you having problems with? Putting the button on each line, or changing the database? Commented Sep 17, 2012 at 15:55
  • 1
    You might want to start by posting the code you've come up with so far. Commented Sep 17, 2012 at 15:55
  • I have no idea how to use the current row, i have created a button on each line Commented Sep 17, 2012 at 16:00
  • show us how far you got till now. Commented Sep 17, 2012 at 16:02
  • What the problem you are facing? Commented Sep 17, 2012 at 16:05

2 Answers 2

2

Create small form with parameters in the cell you want the button to do smth. This is the simpliest approach (approach with refresh).

One more solution is to use AJAX on button click and forward action to some endpoint. This way it would be dynamic and probably what you are want to implement.

Sign up to request clarification or add additional context in comments.

Comments

1
echo "<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>age</th>
<th>position</th>
<th>experience</th>
<th>motivation</th>
<th>date</th>
<th>status</th>
<th>test</th>
</tr>";

while($row = mysql_fetch_array($result))
    {
        echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "<td>" . $row['age'] . "</td>";
    echo "<td>" . $row['position'] . "</td>";
    echo "<td>" . $row['exp'] . "</td>";
    echo "<td>" . $row['motivation'] . "</td>";
    echo "<td>" . $row['date'] . "</td>";
    echo "<td>" . $row['status'] . "</td>";
    echo "<td>" . '<form type="POST"><input type="hidden" name="whatever" value="$row['id']"><input type="submit" name="submit_btn" value="accept"></form>' . "</td>";
    echo "</tr>";

}
    echo "</table>";

in this way, you could get a form in each row of the table. Now, you just need to use php POST function.

if(isset($_POST['submit_btn']))
{
//whatever u need to do
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.