PDA

View Full Version : Adding info to a database


steven21
24-04-2007, 09:09 PM
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

Ben Collier
24-04-2007, 09:16 PM
$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

steven21
24-04-2007, 09:18 PM
after I posted this I had got it working, I have edited and put a new question up

Andrew Taylor
24-04-2007, 09:44 PM
// 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)

Nick Irvine
25-04-2007, 10:26 AM
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:

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 { }

Andrew Taylor
25-04-2007, 11:38 AM
I would agree with Nick, given a choice, individual links is easier and more reliable than checkboxes, especially when dealing with deletions