I have a page where the user can fill in a fotball review. The form is the same for all the teams and its also the same when u want to edit an old review, so I laid the form in a function (ReferatForm).
The thing is that when I try to edit a old rewiew, the radiobutton menu, witch is at the top of the page, also is shown in the window that pops up. Also, the old review data isn't shown in the boxes. I thought it where becouse of the $_SERVER['PHP_SELF'] command, but I tryed everything and nothing works! Someone ho could give me some help? A would realy appreciate it!
Also, I would like the page to redirect to only showing the bullet menu when the submit button ('referat'), for saving the review, is pressed...
This is some parts of my script:
//Function for making a review form
function ReferatForm () {
$today = date("Y-m-d");
print '<form name="referat" method="post" action="' ?><? if (isset($_REQUEST["edit"])) { print ''; } else { print $_SERVER['PHP_SELF']; } print'">
<table width="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><p><span class="litentextSvartNoindent">
<b>Datum:</b></span><b><br>
<input name="date" type="text" value="' ?><? if (isset($_POST['date'])) { print $_POST['date']; } else { print $today; } print'" size="10" maxlength="10">
</b><strong><br>
<br>
Hemma lag:</strong><br>
<b><input name="hometeam" type="text" id="hometeam" value="' ?><? if (isset($_POST['hometeam'])) { print $_POST['hometeam']; } if ($_POST['editsave_referat']) { print ($rad["hometeam"]); } print'" size="30" maxlength="25"></b>
<br>
<b>Borta lag:</b><br>
<input name="awayteam" type="text" id="awayteam" value="' ?><? if (isset($_POST['awayteam'])) { print $_POST['awayteam']; } print'" size="30" maxlength="25">
<br>
<br>
<b>Resultat:</b><br>
'
?>
<input name="endresult" type="text" id="endresult" value="<? if (isset($_POST['endresult'])) { print $_POST['endresult']; } else { print '0-0'; } ?>" size="3" maxlength="5">
<b>(</b>
<input name="halfresult" type="text" id="halfresult" value="0-0" size="3" maxlength="10">
<b>)</b>
<input name="save" type="submit" id="save" value="Nästa..."><br>
<?
//Check how many scoores made, and makes x-amount of boxes for the goalscoorers names
if (isset($_POST['save'])) {
$save = explode("-", $_POST['endresult']);
if ($save[0] != 0){
print '<b>Hemmalagets målgörare:</b><br>';
$a = 0;
while ($a < $save[0]) {
$a++;
print $a . ':' . ' ' . '<input type="text" name="hscoorer[]">' . '<br>';
}
}
if ($save[1] != 0){
print '<b>Bortalagets målgörare:</b><br>';
$b = 0;
while ($b < $save[1]) {
$b++;
print $b . ':' . ' ' . '<input type="text" name="ascoorer[]">' . '<br>';
}
}
}
print '
<INPUT TYPE="HIDDEN" NAME="skicka" VALUE="skicka">
<INPUT TYPE="HIDDEN" NAME="radiobutton" VALUE="' ?><? echo $_POST['radiobutton']; print'">
<br>
<b>Rubrik:</b><br>
<input name="head" type="text" id="head" value="' ?><? if (isset($_POST['head'])) { print $_POST['head']; } else { print ($rad["head"]); } print'" size="50" maxlength="50"><br>
<b><strong>Brödtext:</strong></b> <strong class="litentextSvartNoindent"><br>
<textarea name="bread" cols="50" rows="10" id="bread">' ?><? if (isset($_POST['bread'])) { print $_POST['bread']; } print'</textarea>
</strong>
<br>
<strong>Hemma assist:</strong><br>
<input name="hassist" type="text" id="hassist" value="' ?><? if (isset($_POST['hassist'])) { print $_POST['hassist']; } print'" size="50" maxlength="255"><br>
<strong>Borta assist:</strong><br>
<input name="aassist" type="text" id="aassist" value="' ?><? if (isset($_POST['aassist'])) { print $_POST['aassist']; } print'" size="50" maxlength="255">
<br>
<p><strong>Hemma gula kort:</strong><br>
<input name="hyellow" type="text" id="hyellow" value="' ?><? if (isset($_POST['hyellow'])) { print $_POST['hyellow']; } print'" size="50" maxlength="255"><br>
<strong>Borta gula kort:</strong><br>
<input name="ayellow" type="text" id="ayellow" value="' ?><? if (isset($_POST['ayellow'])) { print $_POST['ayellow']; } print'" size="50" maxlength="255">
</p>
<p><strong>Hemma röda kort:</strong><br>
<input name="hred" type="text" id="hred" value="' ?><? if (isset($_POST['hred'])) { print $_POST['hred']; } print'" size="50" maxlength="255"><br>
<strong>Borta röda kort:</strong><br>
<input name="ared" type="text" id="ared" value="' ?><? if (isset($_POST['ared'])) { print $_POST['ared']; } print'" size="50" maxlength="255">
</p>
<p><strong>Skrivet av:</strong><br>
<input name="writer" type="text" id="writer" value="' ?><? if (isset($_POST['writer'])) { print $_POST['writer']; } print'" size="50" maxlength="50">
</p>
<input name="'?><? if ($_REQUEST["edit"]) { print 'editsave_referat'; } else { print 'referat'; } print'" type="submit" id="referat" value="Spara">
<input name="lag" type="hidden" value="' ?><? if ($_REQUEST['edit']) { print ($_REQUEST['edit']); } else { print $_POST['radiobutton']; } print'">
</td>
</tr>
</table>
</form>';
}//End of ReferatForm
//Function to show old reviews:
function ReferatOld () {
//to change bgcolor for every second row
$query = mysql_query("SELECT * from referat WHERE (lag='$_POST[radiobutton]')") or die(mysql_error());
while ($rad = mysql_fetch_array($query)) {
$i++;
if (($i%2) != 0)
$bgcolor = "#F4F4FF";
else
$bgcolor = "#FFFFFF";
?>
<table bgcolor=<?php echo($bgcolor); ?> width="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="280" class="notiser"><b><? echo($rad["date"]); ?></b></td>
<td width="50" rowspan="2" class="litentext"><div align="center"><strong><a href=javascript:popUp('admin_test3.php?edit=<?php echo($rad["id"]); ?>')><font color=green>Edit</font></a></strong></div></td>
<td width="70" rowspan="2" class="litentext"><div align="center"><strong><a href=javascript:wizard_confirm_demo('admin_test3.php?remove=<? echo($rad["id"]); ?>')><font color=red>Ta
bort</font></a></strong></div></td>
</tr>
<tr>
<td class="notiser"><? echo($rad["head"]); ?><br> </td>
</tr>
</table>
<?
}
}//end of ReferatOld
// Form to show selections of what part u want to edit -->
$radiobutton = isset($_POST['radiobutton'])?$_POST['radiobutton']:""; ?>
<form action="<? if (isset($_REQUEST["edit"])) print ''; else print $_SERVER['PHP_SELF'];?>" method="POST">
<div align="center">
Almanacka:
<input type="radio" name="radiobutton" value="1"<? if ($radiobutton == "1") echo("checked");?>>
Nyheter:
<input type="radio" name="radiobutton" value="2"<? if ($radiobutton == "2") echo("checked");?>><br>
A-lagsmatch:
<input type="radio" name="radiobutton" value="A"<? if ($radiobutton == "A") echo("checked");?>>
B-lagsmatch:
<input type="radio" name="radiobutton" value="B"<? if ($radiobutton == "B") echo("checked");?>>
Damlagsmatch:
<input type="radio" name="radiobutton" value="D"<? if ($radiobutton == "D") echo("checked");?>><br>
<input name="skicka" type="submit" id="skicka" value="Nästa..."><br>
</div>
<hr size="1" noshade>
</form>
<? //Depending of what choice u made and shows the game review form:
if ( ($_POST['radiobutton'] == 'A') OR ($_POST['radiobutton'] == 'B') OR ($_POST['radiobutton'] == 'D') ) {
if (isset($_POST['skicka'])) {
if (isset($_POST['radiobutton'])) {
print ReferatForm ();
print ReferatOld ();
//makes array into one string and renames it to '$hgoalscoorers'
If (isset($_POST['hscoorer'])) {
$score = $_POST['hscoorer'];
$hgoalscoorers = implode(", ", $score);
}
}// if (isset($_POST['radiobutton']))
}//if (isset($_POST['radiobutton']))
}
//To save/delete/edit reviews in or from the database
if (isset($_POST["referat"])) {
$query = mysql_query("insert into referat (date, hometeam, awayteam, endresult, halfresult, head, bread, hscoorer, ascoorer, hassist, aassist, hyellow, ayellow, hred, ared, writer, lag) values ('{$_POST['date']}','{$_POST['hometeam']}','{$_POST['awayteam']}','{$_POST['endresult']}','{$_POST['halfresult']}','{$_POST['head']}','{$_POST['bread']}','{$hgoalscoorers}','{$_POST['ascoorer']}', '{$_POST['hassist']}','{$_POST['aassist']}','{$_POST['hyellow']}','{$_POST['ayellow']}','{$_POST['hred']}','{$_POST['ared']}','{$_POST['writer']}', '{$_POST['lag']}')") or die(mysql_error());
}
if (isset($_GET["remove"])) {
$query = mysql_query("delete from `referat` where id = '{$_GET['remove']}'") or die(mysql_error());
}
if (isset($_REQUEST["edit"])) {
if (isset($_REQUEST["editsave_referat"])) {
echo("<font color=green>Informationen sparades.</font>");
$query = mysql_query("update edit set date='{$_POST['date']}', hometeam='{$_POST['hometeam']}', awayteam='{$_POST['awayteam']}', endresult='{$_POST['endresult']}', halfresult='{$_POST['halfresult']}', head='{$_POST['head']}', bread='{$_POST['bread']}', hscoorer='{$hscoorer}', ascoorer='{$_POST['ascoorer']}', hassist='{$_POST['hassist']}', aassist='{$_POST['aassist']}', hyellow='{$_POST['hyellow']}', ayellow='{$_POST['ayellow']}', hred='{$_POST['hred']}', ared='{$_POST['ared']}', writer='{$_POST['writer']}', lag='{$_POST['lag']}' where id='{$_REQUEST['edit']}'") or die(mysql_error());
}
$query = mysql_query("select * from `referat` where id = '{$_REQUEST['edit']}'") or die(mysql_error());
$rad = mysql_fetch_array($query);
print ReferatForm ();
?>