Well, the page doesn't switch between the functions, if I use $POST...
and if I use $GET, it switches between deleting and editing, but it doesn't call the do_Edit.. Or is the problem somewhere else???
Here's the whole code, and yeah now it's with $_GET:
<?php
if (isset($_GET['action'])){
switch($_GET['action']) {
case 'EditMethod':
EditMethod();
break;
case 'delMethod':
delMethod();
break;
case 'Tallenna':
do_EditMethod();
break;}
else{
ListMethods();
}
function ListMethods(){
global $page ;
$methods_per_page = "20";
if (!isset($page) or $page=="") $page=1;
$nexlimit = $page * $methods_per_page - $methods_per_page;
$result = mysql_query("SELECT * FROM mcards ORDER BY MCID ASC limit $nexlimit,$methods_per_page");
$result_all_rows = mysql_query("SELECT * FROM mcards");
$totalrows = mysql_num_rows($result_all_rows);
echo "<form method=\"post\" name=\"ListMCards\" action=\"methods.php\">
<table border=\"1\" width=\"100%\" id=\"table1\">
<tr>
<td colspan=\"8\" align=\"center\">Menetelmäkortteja yhteensä: ($totalrows)</td>
</tr>
<tr>
<td align=\"center\">ID</td>
<td>Kortin nimi</td>
<td>Viimeksi muokattu</td>
<td align=\"center\">Options</td>
</tr>";
while ($row = mysql_fetch_array($result)){
$MCID = $row['MCID'];
$MCname = $row['MCname'];
$MCcontent = $row['MCcontent'];
$MCadded = $row['MCadded'];
echo "<tr>
<td align=\"center\">$MCID</td>
<td>$MCname</td>
<td>$MCadded</td>
<td align=\"center\">[<a href=\"methods.php?action=EditMethod&MCID=$MCID\">Edit/View</a>]
[ <a href=\"methods.php?action=delMethod&MCID=$MCID\">Delete</a> ]
</td>
</tr>";
}//end while
echo "</table></form>";
// get pages:
$totpages = ceil($totalrows/$methods_per_page);
for ($i=1;$i<=$totpages;$i++) {
if ($i==$page) {
$pages .= " $i ";
} else {
$pages .= " <a href=\"methods.php?action=ListMethods&page=$i\">$i</a> ";
}
}
echo "<br>[ <a href=\"add_mcard.php\">LISÄÄ UUSI MENETELMÄKORTTI</a> ]<br>";
echo "<br><center>Pages: $pages <br>";
}
function delMethod(){
$MCID = $_GET['MCID'];
$result = mysql_query("DELETE from mcards WHERE MCID='$MCID'");
echo "<div align=\"center\" class=\"div\">Menetelmäkortti poistettu. <br>Odota hetki...</div>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=methods.php\">";
}
function EditMethod(){
EditMethodForm();
}
function EditMethodForm(){
//GET THE SELECTED MCARD ID
$MCID = $_GET['MCID'];
$result = mysql_query("SELECT * FROM mcards WHERE MCID='$MCID'");
$row = mysql_fetch_array($result);
//SET THE DETAILS TO VARIABLES
$MCID = $row['MCID'];
$MCname = $row['MCname'];
$MCcontent = $row['MCcontent'];
// PRINT THE FORM
echo" <form method=\"post\" name=\"EditMethodCard\" action=\"methods.php\">
<table><tr><td>Menetelmän nimi: </td>
<td><input type=\"text\" name=\"MCname\" size=\"50\" value=\"$MCname\"></td></tr>
<tr><td colspan=\"2\"><textarea name=\"MCcontent\" id=\"MCcontent\" rows=\"10\" cols=\"40\">
$MCcontent
</textarea><script language=\"javascript1.2\">make_wyzz('MCcontent');</script></td></tr>
<tr><td><input type=\"hidden\" name=\"MCID\ value=\"$MCID\"></td></tr>
<tr><td><input type=\"submit\" name=\"submit\" value=\"Tallenna\"></td>
<td><input type=\"submit\" name=\"cancel\" value=\"Peruuta\"></td></tr></table></form>";
}
function do_EditMethod(){
//SET THE DETAILS TO VARIABLES
$MCID = $_GET['MCID'];
$MCname = $_GET['MCname'];
$MCcontent = $_GET['MCcontent'];
//this function will check fields incase of javascript not working.
if(isset($_GET['MCname']) && ($_GET['MCcontent']) ){
$result = mysql_query("UPDATE mcards SET MCname='$MCname',MCcontent='$MCcontent',MCadded=NOW() WHERE MCID='$MCID'") or die ("Error: ". mysql_error());
if (!$result){
echo "<div align=\"center\" class=\"div\">Error: Tietoja ei voitu päivittää.</div>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"3; URL=methods.php\">";
}
else{
echo "<div align=\"center\" class=\"div\">Informaatio on tallennettu. <br>Odota hetki...</div>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"4; URL=methods.php\">";
}
}
else{
EditMethodForm();
echo "<center><font class=\"error\">Error: Please fill all fields.</font></center>\n";
}
}
?>
And yeah, this is the biggest thing so far I've done with PHP, so plz be gentle with me :o