Update mysql if datagridview link is clicked

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
roipatrick
Forum Newbie
Posts: 2
Joined: Wed Apr 16, 2014 1:30 pm

Update mysql if datagridview link is clicked

Post by roipatrick »

If you just take a look at my code, I have tried everything and I'm sorry if I'm so noob with this language since it was just my second week i think in learning this.

I want to update a data in mysql. In my sql status is defaulted to "In-Progress" so I want to update that to endorsed or approved if the user click the link inside the gridview.

Here's my code for the datagrid

Code: Select all

<div style="height:70%;">
                    <?php
                    $con=mysqli_connect("localhost","root","","leavecalendar");
                    // Check connection
                    if (mysqli_connect_errno())
                    {
                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                    }

                    $result = mysqli_query($con,"SELECT * FROM leavedetails where username = '$loginuser[username]'");

                    echo "<table border='1' class='form-table' width='10%'>
                    <tr>
                          <th>Leave Type</th>
                          <th>Start Date</th>
                          <th>End Date</th>
                          <th>Reason</th>
                          <th>Status</th>
                          <th></th>
                    </tr>";

                    while($row = mysqli_fetch_array($result))
                    {
                    echo "<tr>";
                    echo "<td>" . $row['typeofleave'] . "</td>";
                    //echo "<td>" . $row['stardate'] . "</td>";
                    echo "<td>" . date("m-d-Y", strtotime($row['stardate'])) . "</td>"; 
                    //echo "<td>" . $row['endate'] . "</td>";
                    echo "<td>" . date("m-d-Y", strtotime($row['endate'])) . "</td>"; 
                    echo "<td>" . $row['reason'] . "</td>";
                    echo "<td>" . $row['status'] . "</td>";
                    echo "<td align='center'><a href=\"\">Cancel</a>&nbsp|&nbsp<a href=\"deleteleave.php\">Remove</a></td>";
                    echo "</tr>";
                    }
                    echo "</table>";

                    mysqli_close($con);
                ?>
                </div>

as you can see here echo "<td align='center'><a href=\"\">Cancel</a>&nbsp|&nbsp<a href=\"deleteleave.php\">Remove</a></td>"; if i click the cancel button I want the status in mysql to be updated to endorsed or remove that row in SQL. Please, please I need help since I'm kind of stuck in here for the past 4 days. (Learning can sometimes be a pain specially in my hair)

Can anyone please provide a sample code where I can play around to.

also posted at: http://stackoverflow.com/questions/2311 ... is-clicked and in http://www.webdeveloper.com/forum/forum ... php?16-PHP
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Update mysql if datagridview link is clicked

Post by Celauran »

Cancel clearly isn't going to work because it links to nothing, so let's focus on 'remove' for now. What does deleteleave.php do? What errors are you encountering? I'd think at the very least you'd need to be keeping track of which item you want deleted.
roipatrick
Forum Newbie
Posts: 2
Joined: Wed Apr 16, 2014 1:30 pm

Re: Update mysql if datagridview link is clicked

Post by roipatrick »

Hi sir,

Thans for the reply. Actually the delete.php has no code for now because I dontkknow how to start it with. What i want is to update the row in mysql if I click the delete link. Can you provide a small sample code so that I can play it and maybe i can sove it out.

Thanks.
Post Reply