SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Threaded View
-
Jun 21, 2007, 02:05 #1
- Join Date
- Apr 2007
- Posts
- 398
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Editing data in my database via a form
Hi Guys,
I’d REALLY appreciate some advice if possible
I’ve put together a little script here, which adds football goalscorers to a table in my database:
http://industrialleague.co.uk/test/goals.php?team_id=1
(note clicking the add scorers button adds a dropdown box)
In the SQL table the player_id is the id of the scorer selected from the dropdown and the report_id is the id of an actual match. So for report_id=1 there were two goalscorers for this match.
Now this works fine, but say there were errors in what I entered.
- Ie the wrong player_id was entered as a goalscorer
- or player_id=3 did not actually score and there was one goalscorer
I need to be able to modify this information. So I have three questions:
1) How can I call my page up for report_id=1 ie: http://industrialleague.co.uk/test/g...=1&report_id=1
And there are two scorers boxes dynamically created (rather as one as there are two scorers for this match) which I can then edit data from
2) When I call up the page http://industrialleague.co.uk/test/g...=1&report_id=1 how can I say if there was only one scorer delete a record from the database if there is no value selected in one of the dropdowns while running an update on the other goalscorer as he may be changed?
3) Is there an easier way of recording/editing goalscorers as this way seems very complicated to me!
Here’s my code
PHP Code:<?php
// Start the connection to the database
//Here
// Include functions to get the various values from the dropdown boxes
//Here
if(isset($_REQUEST['Submit']))
{
// Values used for all three tables
$team_id = $_GET['team_id'];
$lastinsert = '1';
// Values to be inserted into reports table
$player_id = $_POST['player_id'];
// IF i'm not getting data then insert into various tables
if(!isset($_GET['report_id']))
{
// Values to be inserted into goals table
foreach($_REQUEST['r'] as $row)
{
mysql_query("INSERT INTO `goals` ( `player_id`,`team_id`, `report_id` ) VALUES ('".$row['player_id']."', '".(int)$_GET['team_id']."', '".$lastinsert."')");
}
}
else
{
$query_one = mysql_query("Update `reports` set player_id='$player_id', team_id='$team_id', report_id='$report_id' where report_id=".$_GET['report_id']);
$msg = "Updated";
}
} //End of POST submit
if(isset($_GET['report_id']))
{
//GET data from Reports Table
$query_one = mysql_query("Select * From goals where report_id=".$_GET['report_id']);
$row = mysql_fetch_array($query_one);
$report_id = $row['report_id'];
}
?>
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
//Function to dynamically add dropdown boxes
function addRow(form) {
var span = document.getElementById("ROW").getElementsByTagName('span')[0];
var obj = span.cloneNode(true);
var count = form.getElementsByTagName("select").length + 1;
var oSel=obj.getElementsByTagName('select')[0];
oSel.setAttribute('tabindex', count);
oSel.name=oSel.name.split("[1]").join("[" + count + "]")
document.getElementById("ROW").appendChild(obj);
}
</script>
<style>
div {clear:both}
input { float:left}
span.next {
float:left;
width:210px;
}
input.inputtext {
width: 200px;
font-size:1.1em;
byear2:2px inset blue;
background:#eee;
}
</style>
</head>
<body>
<form name="reports" method="post" action="">
<input name="button" type="button" onClick="addRow(this.form)" value="Add another Scorer">
<br />
<br />
<!—Dynamic Dropdown boxes start-->
<div id="ROW">
<span class="next">
<?php $p_id = $player_id ? $player_id : ''; ?>
<select class="input" name="r[1]player_id " size="1" style="width: 145" tabindex="1">
<option value="" <?php echo ($p_id == '' ? 'selected="selected"' : ''); ?>>Goalscorer</option>
<?php
$type_array=get_player_names();
foreach ($type_array as $players)
{
print("<option value=\"".$players['player_id']."\""
. ($p_id == $players['player_id'] ? 'selected="selected"' : '')
. ">".$players['player_name']."</option>\n");
}
?>
</select>
</span>
</div>
<!—Dynamic Dropdown boxes end--> <br/><br/>
<input type="submit" name="Submit" value="Submit" class="button">
<input type="reset" name="Reset" value="Reset" class="button">
</p>
</form>
</body>
</html>
Bookmarks