Zepo. Posted October 20, 2007 Share Posted October 20, 2007 It just seems to go to a blank page Acts: case "editrules": include("./includes/rules.php"); editrules($rules); break; case "updater": include("./includes/rules.php"); updater($rules); break; Functions: function editrules($rules){ $rules=mysql_query("SELECT * FROM rules WHERE ladderid='$rules[ladderid]'"); $rules=mysql_fetch_array($rules); echo" <body style='margin:0px'> <div style='margin:10px'> <br /> <table cellpadding='4' cellspacing='0' border='0' width='95%' class='tborder' id='optionsform'> <colgroup span='2'> <col style='width:45%'></col> <col style='width:55%'></col> </colgroup> <tr> <td class='tcat' colspan='2'> <b>Rules Manager</b> </td> </tr> <form method='post'> <tr valign='top'> <td class='optiontitle' colspan='2'><div align='center'>Rules For Ladder ID $rules[ladderid]</div></td> </tr> <tbody id='tbody_keywords'> <tr valign='top'> <td class='alt1'><div class='smallfont' align='center'> <textarea name='rules[rules]' rows='20' cols='80'>$rules[rules]</textarea><br /><br /> <input type='hidden' name='rules[ladderid]' value='$rules[ladderid]'> <input type='hidden' name='act' value='updater'> <input type='submit' name='submit' value='Update Rules >>'></td> </form></div> </td> </tr> </table>"; } function updater($rules){ global $config; include("./check.php"); $rules[rules]=allowhtml($rules[rules]); mysql_query("UPDATE rules SET rules='$rules[rules]' WHERE ladderid='$rules[ladderid]'"); $adminlog[admin]="{$_SESSION['name']}"; $adminlog[details]="[Edited Rules] Edit Rules: Ladder ID: $rules[ladderid]"; adminlog($adminlog); echo" <body style='margin:0px'> <div style='margin:10px'> <br /> <form method='post'> <table cellpadding='4' cellspacing='0' border='0' width='95%' class='tborder' id='optionsform'> <colgroup span='2'> <col style='width:45%'></col> <col style='width:55%'></col> </colgroup> <tr> <td class='tcat' colspan='2'> <b>Rules Manager</b> </td> </tr> <tr valign='top'> <td class='optiontitle' colspan='2'><div>Updated</div></td> </tr> <tbody id='tbody_keywords'> <tr valign='top'> <td class='alt1'><div class='smallfont' align='center'> <b> The rules have been updated for ladder ID $rules[ladderid]. You may wish to make an announcement on the ladder that has been updated.<br /> <br /> </b></td> </tr> </tbody> </table>"; } Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/ Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Post entire relevant code on both pages (including the entire switch statement you only posted part of it). Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374232 Share on other sites More sharing options...
Zepo. Posted October 20, 2007 Author Share Posted October 20, 2007 The switch statements way too long to post, but everything works but that. Entire file for functions <? if($_SESSION['rights'] == 100){ function selectrules(){ global $config; $ladders=mysql_query("SELECT id,name FROM ladders ORDER BY name"); while(list($id,$name)=mysql_fetch_row($ladders)){ $ladderlist.="<option value='$id'>$name</option>\n"; } echo" <body style='margin:0px'> <div style='margin:10px'> <br /> <form method='post'> <table cellpadding='4' cellspacing='0' border='0' width='95%' class='tborder' id='optionsform'> <colgroup span='2'> <col style='width:45%'></col> <col style='width:55%'></col> </colgroup> <tr> <td class='tcat' colspan='2'> <b>Rules Manager</b> </td> </tr> <tr valign='top'> <td class='optiontitle' colspan='2'><div>Select Ladder</div></td> </tr> <tbody id='tbody_keywords'> <tr valign='top'> <td class='alt1'><div class='smallfont' align='center'> <select name='rules[ladderid]'> $ladderlist </select><br /><br /><input type='hidden' name='act' value='editrules'> <input type='submit' name='submit' value='Edit Rules >>'></td> </form></td> </tr> </tbody> </table>"; } function editrules($rules){ $rules=mysql_query("SELECT * FROM rules WHERE ladderid='$rules[ladderid]'"); $rules=mysql_fetch_array($rules); echo" <body style='margin:0px'> <div style='margin:10px'> <br /> <table cellpadding='4' cellspacing='0' border='0' width='95%' class='tborder' id='optionsform'> <colgroup span='2'> <col style='width:45%'></col> <col style='width:55%'></col> </colgroup> <tr> <td class='tcat' colspan='2'> <b>Rules Manager</b> </td> </tr> <form method='post'> <tr valign='top'> <td class='optiontitle' colspan='2'><div align='center'>Rules For Ladder ID $rules[ladderid]</div></td> </tr> <tbody id='tbody_keywords'> <tr valign='top'> <td class='alt1'><div class='smallfont' align='center'> <textarea name='rules[rules]' rows='20' cols='80'>$rules[rules]</textarea><br /><br /> <input type='hidden' name='rules[ladderid]' value='$rules[ladderid]'> <input type='hidden' name='act' value='updater'> <input type='submit' name='submit' value='Update Rules >>'></td> </form></div> </td> </tr> </table>"; } function updater($rules){ global $config; include("./check.php"); $rules[rules]=allowhtml($rules[rules]); mysql_query("UPDATE rules SET rules='$rules[rules]' WHERE ladderid='$rules[ladderid]'"); $adminlog[admin]="{$_SESSION['name']}"; $adminlog[details]="[Edited Rules] Edit Rules: Ladder ID: $rules[ladderid]"; adminlog($adminlog); echo" <body style='margin:0px'> <div style='margin:10px'> <br /> <form method='post'> <table cellpadding='4' cellspacing='0' border='0' width='95%' class='tborder' id='optionsform'> <colgroup span='2'> <col style='width:45%'></col> <col style='width:55%'></col> </colgroup> <tr> <td class='tcat' colspan='2'> <b>Rules Manager</b> </td> </tr> <tr valign='top'> <td class='optiontitle' colspan='2'><div>Updated</div></td> </tr> <tbody id='tbody_keywords'> <tr valign='top'> <td class='alt1'><div class='smallfont' align='center'> <b> The rules have been updated for ladder ID $rules[ladderid]. You may wish to make an announcement on the ladder that has been updated.<br /> <br /> </b></td> </tr> </tbody> </table>"; } } ?> It works untill you try to update. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374233 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 One thing I noticed right off is function editrules($rules){ $rules=mysql_query("SELECT * FROM rules WHERE ladderid='$rules[ladderid]'"); $rules=mysql_fetch_array($rules); Doesn't make sense. You pass the function the variable rules, which is automatically overwritten by the query followed by overwritten again by te fetch array. It's completely formatted wrong, you are going to want to rewrite the whole function. basically you want the variable you are passing to it named differently than those, and you want both of them different. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374239 Share on other sites More sharing options...
Zepo. Posted October 20, 2007 Author Share Posted October 20, 2007 One thing I noticed right off is function editrules($rules){ $rules=mysql_query("SELECT * FROM rules WHERE ladderid='$rules[ladderid]'"); $rules=mysql_fetch_array($rules); Doesn't make sense. You pass the function the variable rules, which is automatically overwritten by the query followed by overwritten again by te fetch array. It's completely formatted wrong, you are going to want to rewrite the whole function. basically you want the variable you are passing to it named differently than those, and you want both of them different. That is because the ladderid variable is the only passed variable, so im using that to get the rest of them. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374241 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 either way, functions just do not operate that way. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374243 Share on other sites More sharing options...
Zepo. Posted October 20, 2007 Author Share Posted October 20, 2007 Well the main thing im looking for is how to get the function to actually show up....its just a white page.. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374247 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Because (as I have mentioned 2 seperate times) the function is done incorrectly. I do not feel like rewriting the whole thing. Go to www.google.com and do a search on "Creating functions in php". Spend a couple of hours studying about function creation in php and basic function rules. Then try to rewrite the function so it'll work and repost here when you have problems. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374251 Share on other sites More sharing options...
MadTechie Posted October 20, 2007 Share Posted October 20, 2007 Cleaned up function editrules($rules){ $rules=mysql_query("SELECT * FROM rules WHERE ladderid='{$rules['ladderid']}'"); $rules=mysql_fetch_array($rules); echo" <body style='margin:0px'> <div style='margin:10px'> <br /> <table cellpadding='4' cellspacing='0' border='0' width='95%' class='tborder' id='optionsform'> <colgroup span='2'> <col style='width:45%'></col> <col style='width:55%'></col> </colgroup> <tr> <td class='tcat' colspan='2'> <b>Rules Manager</b> </td> </tr> <form method='post'> <tr valign='top'> <td class='optiontitle' colspan='2'><div align='center'>Rules For Ladder ID {$rules['ladderid']}</div></td> </tr> <tbody id='tbody_keywords'> <tr valign='top'> <td class='alt1'><div class='smallfont' align='center'> <textarea name='rules[rules]' rows='20' cols='80'>{$rules['rules']}</textarea><br /><br /> <input type='hidden' name='{rules['ladderid']}' value='{$rules['ladderid']}'> <input type='hidden' name='act' value='updater'> <input type='submit' name='submit' value='Update Rules >>'></td> </form></div> </td> </tr> </table>"; } function updater($rules){ global $config; include("./check.php"); $rules['rules']=allowhtml($rules['rules']); mysql_query("UPDATE rules SET rules='{$rules['rules']}' WHERE ladderid='{$rules['ladderid']}'"); $adminlog[admin]="{$_SESSION['name']}"; $adminlog[details]="[Edited Rules] Edit Rules: Ladder ID: {$rules['ladderid']}"; adminlog($adminlog); echo" <body style='margin:0px'> <div style='margin:10px'> <br /> <form method='post'> <table cellpadding='4' cellspacing='0' border='0' width='95%' class='tborder' id='optionsform'> <colgroup span='2'> <col style='width:45%'></col> <col style='width:55%'></col> </colgroup> <tr> <td class='tcat' colspan='2'> <b>Rules Manager</b> </td> </tr> <tr valign='top'> <td class='optiontitle' colspan='2'><div>Updated</div></td> </tr> <tbody id='tbody_keywords'> <tr valign='top'> <td class='alt1'><div class='smallfont' align='center'> <b> The rules have been updated for ladder ID {$rules['ladderid']}. You may wish to make an announcement on the ladder that has been updated.<br /> <br /> </b></td> </tr> </tbody> </table>"; } Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374252 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 You don't seem to be getting it. Unless there is something I am unaware of here. function editrules($rules){ $rules=mysql_query("SELECT * FROM rules WHERE ladderid='{$rules['ladderid']}'"); $rules=mysql_fetch_array($rules); That is NOT usable. You PASS a parameter to the functionnamed rules. Then it's overwritten by the query and again by the array. Again, even if you have an array inside $rules the entire thing is overwritten with the first $rules= This function is not usable. IF someone knows otherwise please explain. On another note if you are echoing giant blocks of html consider EOD. (I think that's what it's called again). Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374257 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 You also seem to be incorrectly referencing array's inside the echo statement. My point overall, this entire function is a mess and need an entire rewrite. Again, go to google and do some studying. Within a few hours you can rewrite it with new knowledge, and have a very good/usable function. If you have problems at that point feel free to repost. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374259 Share on other sites More sharing options...
MadTechie Posted October 20, 2007 Share Posted October 20, 2007 //This line. we all know (only fix was correcting the use of the array) $rules=mysql_query("SELECT * FROM rules WHERE ladderid='{$rules['ladderid']}'"); //Step 1, Fetch_array -> Pass data ($rules), //Step 2, return data and set to $rules. $rules=mysql_fetch_array($rules); as for the function.. i fixed a few common mistakes.. i didn't review the logic my basic fix refers to the $rules[ladderid] 's, if it makes a differents then cool, if not.. well theirs a few bugs out of the way Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374262 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 I wasn't referring to you specifically. More of just the 2 functions. They annoy me, I would rewrite them but I just don't feel like the effort right now. Quote Link to comment https://forums.phpfreaks.com/topic/74115-switch-case/#findComment-374265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.