Jump to content

Edit and Delete data in a php table using a link


ohkered

Recommended Posts

hi guys,

 

Basically, what I did was i displayed my database information by a table. on which on the last column there's 2 link, which is edit and delete.

 

My question is what code should i put that when I click on the edit or delete link, so that it can indicate that particular data (or ID) has been selected (or stored) ?

 

sorry for my poor english.

hope u guys understand what i need.

thanks and help pls  :shrug:

 

SQLversion: 5.5.8

 

<?php

//connects to database
require('connect.php');

//select table
$select = mysql_query("SELECT * FROM studentinfo") or die('No table exist!');
$numrows = mysql_num_rows($select);

        echo <<<EOM
                <table border='1'>
                <tr>
                        <th>Student Number</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Email Address</th>
                        <th>Phone Number</th>
                        <th>Actions</th>
                </tr>
EOM;

while ($row = mysql_fetch_assoc($select))
{
        echo <<<EOM
                <tr>
                        <td>{$row['StudentNumber']}</td>
                        <td>{$row['FirstName']}</td>
                        <td>{$row['LastName']}</td>
                        <td>{$row['EmailAddr']}</td>
                        <td>{$row['PhoneNumber']}</td>
                        <td><a href='update.php'>Edit</a>  <a href='delete.php'>Delete</a></td>

                </tr>

EOM;
}

        echo <<<EOTABLE

        </table>

EOTABLE;

?>

I'm guessing the StudentNumber is unique? Something by which you can identify one and only one record in the table?

 

Example:

update.php?sn=(student number goes here)

if (isset($_GET["sn"])) {
    $sn = (int)$_GET["sn"];
    // do whatever
} else {
    // no student number given. redirect someplace? show an error message?
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.