how can I delete athletes from my database

Posted on 2012-09-09
Last Modified: 2012-09-13
Hi I need to be able to add a delete colum to my display table shown below, so that I can successfully remove any number of athletes. I would then like to be able to provide some feedback that the athletes where successfully removed. Please help as I'm new to this and I'm struggling to understand it all

include '';

$query = "SELECT image, lname, fname, gender, sport, name FROM tblolympicAthletes
                  JOIN tblCountry ON (tblolympicAthletes.countrynationcodeID = tblCountry.countrynationcodeID)
order by lname";
$result = mysql_query($query);

echo"<tr><th>Image</th><th>Last Name</th><th>First Name</th><th>Gender</th><th>sport</th><th>Country</th></tr>";
while ($row = mysql_fetch_assoc($result))
      foreach($row as $index=>$value)
      if ($index == 'image')
                  echo("<td><img src=$value /></td>");

Also here is my Athlete table

include '';

$createTable = "DROP TABLE IF EXISTS tblolympicAthletes";
$result = mysql_query($createTable);

$createTable = "create table tblolympicAthletes
athleteID  int(6) not null auto_increment,
image   varchar(20) not null,
lname      varchar(20) not null,
fname      varchar(20) not null,
gender      varchar(1) not null,
sport      varchar(50) not null,
countrynationcodeID int(5) not null,


$result = mysql_query($createTable);

function createRecordA ($image, $lname, $fname, $gender, $sport, $countrynationcodeID)
$insertQuery = "insert into tblolympicAthletes (image, lname, fname, gender, sport, countrynationcodeID) values ('$image', '$lname',
'$fname', '$gender', '$sport', '$countrynationcodeID')";
$result = mysql_query($insertQuery);
createRecordA('dan.jpg alt=dan', 'Olaru', 'Dan', 'M', 'Archery', '1');
createRecordA('Gemma.jpg alt=gemma', 'Flynn', 'Gemma', 'F', 'Hockey', '2');
createRecordA('Sona.jpg alt=sona', 'Bernardova', 'Sona', 'F', 'Synchronised-swimming', '3');
createRecordA('Robert.jpg alt=robert', 'Elder', 'Robert', 'M', 'Archery', '4');
createRecordA('Gian.jpg alt=gian', 'Sibello', 'Gianfranco', 'M', 'Sailing', '5');
createRecordA('Charlotte.jpg alt=charlotte', 'Harrison', 'Charlotte', 'F', 'Hockey', '2');
createRecordA('Anne-marie.jpg alt=anne-marie',  'Rindom', 'Anne-Marie', 'F', 'Sailing', '6');
createRecordA('Anna.jpg alt=anna', 'Kulkina', 'Anna', 'F', 'Synchronised-swimming', '7');
createRecordA('C.jpg alt=c', 'Eskilsson', 'Christofer', 'M', 'Diving', '8');
createRecordA('Ger.jpg alt=ger',  'Owens', 'Ger', 'M', 'Sailing', '9');
createRecordA('Katie.jpg alt=katie',  'Skelton', 'Katie', 'F', 'Synchronised-swimming', '10');
createRecordA('Emily.jpg alt=emily',  'Naylor', 'Emily', 'F', 'Hockey', '2');
createRecordA('Anna1.jpg alt=anna',  'Pysmenska', 'Anna', 'F', 'Diving', '11');
createRecordA('Xi.jpg alt=xi',  'Dai', 'Xiaoxiang', 'M', 'Archery', '12');
createRecordA('Olena.jpg alt=olena',  'Fedorova', 'Olena', 'F', 'Diving', '11');

Question by:stumpboss
    LVL 27

    Accepted Solution

    stumpboss, I hate to throw cold water on your question, but the rules of EE prohibit experts from helping you do a scholastic assignment in this blanket way.

    We are allowed to answer specific questions if you can rephrase to ask about some point where you are having trouble, but not to guide you step by step through your assignment.

    Author Comment

    ok sorry didn't  think I was doing that, just wanted some help with one piece of the puzzle
    LVL 27

    Expert Comment

    Which specific piece and what is your question about it?

    Author Comment

    how do I add a delete radio button to my table
    LVL 27

    Assisted Solution

    You have a database "table" and an html "table".  I'm assuming you want to add a delete button to the html table where you are displaying the info to some user.  Right?  And then when that button is pushed, you want to remove that athlete from the database table?

    You will need to create a "form" and a submit button.  The submit button will say "Delete" on it, and the form will contain a hidden input with the athlete id for that athlete, so when the button is clicked, the form is triggered and the id of that athlete passed to your form processing action script.

    Start by reading about <form and how it works.  Then create a <form within the html table row for each athlete.  Within the form, put a hidden input and a submit button.

    In the action script that the form triggers, retrieve that input, use the id to delete from your database, and then echo out a confirmation message.

    Things to read about:
    html <form .....
    html <input type=hidden ....
    html <input type=submit ....
    php array $_POST
    php echo
    LVL 27

    Expert Comment

    If you want to get a little more sophisticated, you can use checkboxes for each athlete and a single submit button to delete all the checked ones.  (Read about <input type=checkbox)

    You could use a radio button to select exactly one of the athletes if you really want a radio button, instead of a form in each line of the table (Read about <input type=radio)

    Author Comment

    Thanks for the info I've looked around at all your suggestions and had ago at it, but still I'm unable to accomplish it

    This is the result I get

    Author Comment

    what I really need is the  th along the top and all records displayed in the td like this

    lname               fname            gender            sport             country              population          delete

    mike                 may                   m                    ......               ........                      .......             checkbox

    Then I would be able to select the athletes to delete as you suggested earlier can you give me any clues please
    LVL 27

    Expert Comment

    Clue:  Read about formating HTML tables, in particular how to use the <table>, <tr> and <td> tags to format it the way you want it to look.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (, A SQLite Tidbit: Quick Numbers Table Generation (…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now