Adding info to a database

Discussion in 'PHP / Perl / Ruby on Rails' started by steven21, Apr 24, 2007.

  1. steven21 Ice Hockey Know All

    Last year Nick made an admin area for my ukicehockey site, I have tried to add a bit that allows me to add a player from that admin area and I am almost done, except one bit.

    I have added a section to add players into my database, but I dont know how I would start to delete one, anyone got any suggestions for me?

    Ideally I would have it in the same area where I edit my player stats - i.e. tick a box then delete button
  2. Ben Collier CSNM Customer

    PHP:
     
    $PlayerID 
    $_POST['PlayerID'];
    $TeamID $_POST['TeamID'];
    $Team $_POST['Team'];
    $Player $_POST['Player'];
    $Games $_POST['Games'];
    $Goals $_POST['Goals'];
    $Assists $_POST['Assists'];
    $PIM $_POST['PIM'];
    $Points $_POST['Points'];
    $GamesCup $_POST['GamesCup'];
    $GoalsCup $_POST['GoalsCup'];
    $AssistsCup $_POST['AssistsCup'];
    $PIMCup $_POST['PIMCup'];
    $PointsCup $_POST['PointsCup'];
    $GamesNPL $_POST['GamesNPL'];
    $GoalsNPL $_POST['GoalsNPL'];
    $AssistsNPLup $_POST['PIMNPL'];
    $PointsNPL $_POST['PointsNPL'];
    $GamesPO $_POST['GamesPO'];
    $GoalsPO $_POST['GoalsPO'];
    $AssistsPO $_POST['AssistsPO'];
    $PIMPO $_POST['PIMPO'];
    $PointsPO $_POST['PointsPO'];
    $Nationality $_POST['Nationality'];
     
    This doesn't seem to have Player in it?

    This doesn't have team in it, but team name instead?
    $sql = "INSERT INTO snl_players VALUES ('$PlayerID', '$TeamID', '$TeamName', '$Player', '$Games', ....

    Not sure if I've got the right end of the stick, I have no knowledge in php so maybe I'm missing something!

    Ben
  3. steven21 Ice Hockey Know All

    after I posted this I had got it working, I have edited and put a new question up
  4. Andrew Taylor CS New Media Staff

    PHP:
    // If checked for deletion, remove it

    if(isset($_POST['deleteFile'])){
    $test $_POST[deleteFile];
    foreach( 
    $test as $key => $value){

    $query "DELETE FROM table_name WHERE table_field_id = '$value";
       
    mysql_query($query) or die('Error : ' mysql_error());

    }
     }
    With the checkboxes called:
    <input type="checkbox" name="deleteFile[$file]" value="$file">

    That should hopefully work (mangled from an image deletion script)
  5. Nick Irvine Secretly the main man

    Sorry for my late reply steven.

    Personally I would do it a different way, have a little link that is displayed next to each player name with the player id number in the link. So that when clicked deletes the player.

    ie something like this:

    viewplayers.php?act=deleteplayer&id=124

    Then on top of the page:

    PHP:
    if ($act=deleteplayer) {
    $query "DELETE FROM `table_name` WHERE `player_id` = '$id LIMIT 1"
       
    mysql_query($query) or die('Error : ' mysql_error()); 
    echo (
    "Player Deleted"); } else { } 
  6. Andrew Taylor CS New Media Staff

    I would agree with Nick, given a choice, individual links is easier and more reliable than checkboxes, especially when dealing with deletions

Share This Page