Jump to content

Switch Case


Zepo.

Recommended Posts

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>";
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
}

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

//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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.