Jump to content

Recommended Posts

Hi, I am making an ability points assigning page, and I tried to shorten my code with functions, I was wondering if anyone could please point out some errors if you have some time. Thank you. Derek

 

here are the errors I'm getting

 

Notice: Undefined index: reset in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 45

Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: dexterity in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: constitution in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: intelligence in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: dexterity in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: constitution in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: intelligence in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: dexterity in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: constitution in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: intelligence in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: dexterity in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: constitution in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: intelligence in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: dexterity in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: constitution in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: intelligence in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: dexterity in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 64

Notice: Undefined index: constitution in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Notice: Undefined index: intelligence in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65

Warning: Missing argument 1 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 137 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Warning: Missing argument 2 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 137 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Warning: Missing argument 3 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 137 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Notice: Undefined variable: postAbil in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 108

Warning: Missing argument 1 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 138 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Warning: Missing argument 2 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 138 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Warning: Missing argument 3 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 138 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Notice: Undefined variable: postAbil in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 108

Warning: Missing argument 1 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 139 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Warning: Missing argument 2 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 139 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Warning: Missing argument 3 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 139 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 106

Notice: Undefined variable: postAbil in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 108

 

and here is my code for the page

 

<?php
session_start();

// permanent character ability points assigned from form into these session vars
$_SESSION['playerStrength']='';
$_SESSION['playerWisdom']='';
$_SESSION['playerCharisma']='';
$_SESSION['playerConstitution']='';
$_SESSION['playerIntelligence']='';
$_SESSION['playerDexterity']='';

///variables to say that the number has already been used
$sixteenUsed='';
$fourteenUsed='';
$thirteenUsed='';
$twelveUsed='';
$elevenUsed='';
$tenUsed='';
//////////////////////////
$playerStrength='';
$playerWisdom='';
$playerCharisma='';
$playerIntelligence='';
$playerDexterity='';
$playerConstitution='';

$assignMessage='';


//ability points to disappear after used

$sixteen=16;
$fourteen=14;
$thirteen=13;
$twelve=12;
$eleven=11;
$ten=10;


/////////////////////////////////////////////////////////////////////////////////////
echo "<pre>".print_r($_POST, 1)."</pre>";


///////////////////////////////reset the points//////////////////////
if($_POST['reset'])
{
$_SESSION['playerWisdom']='';
$_SESSION['playerConstitution']='';
$_SESSION['playerStrength']='';
$_SESSION['playerCharisma']='';
$_SESSION['playerDexterity']='';
$_SESSION['playerIntelligence']='';

}
///////////////////////////////////////////////////////////////////////

//if 16 already used from form, echo out nothing instead of '16' at the top of page.
//then make the number Used equal to true so we can use it later this function has & 
//in front of the variable,passing by reference, dont do it for superglobals like 
//$_POST.
//ONLY VARIABLES CAN BE PASSED BY REFERENCE, NOT NUMBERS OR STRINGS.
function disappearNum($abilValue,&$abilNum,&$usedNum)
{
if($_POST['strength']==$abilValue || $_POST['wisdom']==$abilValue || $_POST['charisma']==$abilValue || $_POST['dexterity']==$abilValue
|| $_POST['constitution']==$abilValue || $_POST['intelligence']==$abilValue)
{
$abilNum=''; 
$usedNum=true;
}
}
/////////////////////////////////////////
disappearNum(16,$sixteen,$sixteenUsed);//passing arguments into the function
disappearNum(14,$fourteen,$fourteenUsed);
disappearNum(13,$thirteen,$thirteenUsed);
disappearNum(12,$twelve,$twelveUsed);
disappearNum(11,$eleven,$elevenUsed);
disappearNum(10,$ten,$tenUsed);
//
//WE ARE GOING TO MAKE THE BELOW INTO A FUNCTION BY COMPARING THE COPIES, NOTING WHAT
//IS DIFFERENT, AND MAKING THOSE OUR FUNCTION PARAMETERS, THEN WE CALL THE FUNCTION
//AND PASS THE VALUES IN, UNLESS THE VARIABLES ARE SUPERGLOBALS, WE PUT A & BEFORE 
//THE DOLLAR SIGN IN OUR PARAMETER.


//if 16 already used from form, echo out nothing instead of '16' at the top of page.
//then make the number Used equal to true so we can use it later

/*
if($_POST['strength']==16 || $_POST['wisdom']==16 || $_POST['charisma']==16 || $_POST['dexterity']==16
|| $_POST['constitution']==16 || $_POST['intelligence']==16)
{
$sixteen=''; 
$sixteenUsed=true;
}

if($_POST['strength']==14 || $_POST['wisdom']==14 || $_POST['charisma']==14 || $_POST['dexterity']==14
|| $_POST['constitution']==14 || $_POST['intelligence']==14)
{
$fourteen=''; 
$fourteenUsed=true;
}
*/

//ONLY VARIABLES CAN BE PASSED BY REFERENCE NOT NUMBERS OR STRINGS.
////////////////////////////////////////////////////////////////////////////////////
function assignAbility(&$postAbil,&$playerAbil,$ability)
{
if(!empty($_POST[$postAbil]))
{
	if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
	{
		return 'Sorry you have already used this number.';
	}
	elseif($_POST['$postAbil']==16 || $_POST['$postAbil']==14 || $_POST['$postAbil']==13
	|| $_POST['$postAbil']==12 ||$_POST['$postAbil']==11 || $_POST['$postAbil']==10)
	{
		$_SESSION['playerAbil']=$_POST['strength'];
		$assignMessage='You have assigned '.$_SESSION['playerAbil'].' to '.$ability;
	}
	else 
	{
		return 'please enter a correct number.';
	}

	return ''; //so we dont get an error.


}
}
assignAbility($strength,$playerStrength,'Strength'); // passing in the arguments.
assignAbility($wisdom,$playerWisdom,'Wisdom'); 
assignAbility($dexterity,$playerDexterity,'Dexterity'); 
assignAbility($intelligence,$playerIntelligence,'Intelligence'); 
assignAbility($charisma,$playerCharisma,'Charisma'); 
assignAbility($contitution,$playerConstitution,'constitution'); 

$usedMessage=assignAbility();
$assignMessage=assignAbility();
$error=assignAbility();  //make the return values echo out via these variables

//AGAIN, WE ARE GOING TO USE THE BELOW TWO COPIES, NOTE THE DIFFERENCES, MAKE THOSE 
//DIFFERENCES THE FUNCTION PARAMETERS, THEN PASS THE ARGUMENTS IN THE FUNCTION CALL.
//if they've already assigned this point, say sorry message, otherwise, assign point.
//we copy the large copy into the function and then add the parameters where the 
//specific names were.

/*if(!empty($_POST['strength']))
{
if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
{
	$usedMessage='Sorry you have already used this number.';
}
elseif($_POST['strength']==16 || $_POST['strength']==14 || $_POST['strength']==13
|| $_POST['strength']==12 ||$_POST['strength']==11 || $_POST['strength']==10)
{
	$_SESSION['playerStrength']=$_POST['strength'];
	$assignMessage='You have assigned '.$_SESSION['playerStrength'].' to Strength';
}
else 
{
	$error="please enter a correct number.";
}
}
if(!empty($_POST['wisdom']))
{
if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
{
	$usedMessage='Sorry you have already used this number.';
}
elseif($_POST['wisdom']==16 || $_POST['wisdom']==14 || $_POST['wisdom']==13
|| $_POST['wisdom']==12 ||$_POST['wisdom']==11 || $_POST['wisdom']==10)
{
	$_SESSION['playerWisdom']=$_POST['wisdom'];
	$assignMessage='You have assigned '.$_SESSION['playerWisdom'].' to Wisdom';
}
else 
{
	$error="please enter a correct number.";
}
}


*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Dereks Dragon Game</title>
<style type="text/css">
table {
width: 30%;
background-color:#CCCCCC;
border: 1px white solid;
}
</style>

</head>
<body>
<h3 align="center"> Welcome to Derek's Dragon Games</h3>
<br /><br /><p align='center'> <a href="choose_class.php">Go back to Class choose menu</a></p><br /><br />
<p align="center">Please assign the following ability points to your Abilities for your <?php echo "<strong>".$_SESSION['race']." ".$_SESSION['class']."</strong>.";?><br /><br /></p>
<p align="center"><strong><?php echo $sixteen.", ".$fourteen .", ". $thirteen.", ".$twelve.", ".$eleven.", ".$ten.". ";?></strong></p> 

<strong>Abilities:</strong><br /><br />
<?php echo $assignMessage;?>
<?php echo $usedMessage;?>
<?php echo $error;?>
<table><tr><td><strong>Strength (Str):</strong> measures your character’s physical
power. It’s important for most characters who fight
hand-to-hand. Clerics, fighters, paladins, rangers, and warlords have powers based on Strength.</td></tr>
</table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Strength:</strong><input type="text"  size="10" maxlength="2" name="strength"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Constitution: (Con)</strong> represents your character’s
health, stamina, and vital force. All characters benefit from a high Constitution score. Many warlock powers are based on Constitution.</td></tr></table><table> 
<tr><td><form action="ability_points.php" method="post"><strong>Constitution:</strong><input type="text" size="10" maxlength="2" name="contitution"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Dexterity:</strong>measures hand-eye coordination,
agility, reflexes, and balance. Many ranger and rogue powers are based on
Dexterity.</td></tr>
</table><table> 
<tr><td><form action="ability_points.php" method="post"><strong>Dexterity:</strong><input type="text"   size="10" maxlength="2"  name="dexterity" > <input type="submit"  value="Assign Points"/> </form></td></tr> 
</table><br /><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Intelligence (Int):</strong> Intelligence (Int) describes how well your character
learns and reasons. Wizard powers are based on Intelligence.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Intelligence:</strong><input type="text" size="10" maxlength="2" name="intelligence"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<br /> 
<?php echo $usedMessage;?>
<table><tr><td><strong>Wisdom (Wis):</strong> measures your common sense, perception,
self-discipline, and empathy. You use your Wisdom score to notice details, sense danger, and get a
read on other people.Many cleric powers are based on Wisdom.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Wisdom:</strong><input type="text"  size="10" maxlength="2" name="wisdom" > <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br /><br /> 
<?php echo $usedMessage;?>
<table><tr><td><strong>Charisma (Cha):</strong> measures your force of personality,
persuasiveness, and leadership.Many paladin and warlock powers are based on
Charisma.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Charisma:</strong><input type="text" size="10" maxlength="2" name="charisma"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br /><br /> 
<table><tr><td><form action="ability_points.php" method="post"><strong><input type="submit" value="Reset abilities" name="reset" /></form></form></td></tr>
<br /> 
</table>
</body>
</html>

 


Have you bothered to try and sort it out yourself? If you take the time to actually read the error messages, they help you figure out what's wrong, and it's fairly self-explanatory..."Undefined Index" means you are attempting to call an array element that doesn't exist.  "Missing Argument" means you are not passing enough arguments to a function call.  "Undefined Variable" attempting to use a variable that doesn't exist.  Pretty self explanatory...and it tells you what line number and everything.  Those are easy errors to fix, there's no reason you can't figure them out yourself.

cool I followed your advice and narrowed it down to these errors. Please if anyone can help me I'd appreciate it as I'm having trouble seeing what I'm doing wrong with the 2 functions in there.

 

here are the errors

 

Warning: Missing argument 1 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 145 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Warning: Missing argument 2 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 145 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Warning: Missing argument 3 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 145 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Notice: Undefined variable: postAbil in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 116

Warning: Missing argument 1 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 146 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Warning: Missing argument 2 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 146 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Warning: Missing argument 3 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 146 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Notice: Undefined variable: postAbil in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 116

Warning: Missing argument 1 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 147 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Warning: Missing argument 2 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 147 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Warning: Missing argument 3 for assignAbility(), called in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 147 and defined in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 114

Notice: Undefined variable: postAbil in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 116

 

and here is the code that has less errors in it.

 

<?php
session_start();

// permanent character ability points assigned from form into these session vars
$_SESSION['playerStrength']='';
$_SESSION['playerWisdom']='';
$_SESSION['playerCharisma']='';
$_SESSION['playerConstitution']='';
$_SESSION['playerIntelligence']='';
$_SESSION['playerDexterity']='';

///variables to say that the number has already been used
$sixteenUsed='';
$fourteenUsed='';
$thirteenUsed='';
$twelveUsed='';
$elevenUsed='';
$tenUsed='';
//////////////////////////
$playerStrength='';
$playerWisdom='';
$playerCharisma='';
$playerIntelligence='';
$playerDexterity='';
$playerConstitution='';

$assignMessage='';


//ability points to disappear after used

$sixteen=16;
$fourteen=14;
$thirteen=13;
$twelve=12;
$eleven=11;
$ten=10;

///the following prevents this error
//Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65
$_POST['reset']='';
$_POST['strength']='';
$_POST['wisdom']='';
$_POST['charisma']='';
$_POST['constitution']='';
$_POST['intelligence']='';
$_POST['dexterity']='';
/////////////////////////////////////////////////////////////////////////////////////
echo "<pre>".print_r($_POST, 1)."</pre>";


///////////////////////////////reset the points//////////////////////
if($_POST['reset'])
{
$_SESSION['playerWisdom']='';
$_SESSION['playerConstitution']='';
$_SESSION['playerStrength']='';
$_SESSION['playerCharisma']='';
$_SESSION['playerDexterity']='';
$_SESSION['playerIntelligence']='';

}
///////////////////////////////////////////////////////////////////////

//if 16 already used from form, echo out nothing instead of '16' at the top of page.
//then make the number Used equal to true so we can use it later this function has & 
//in front of the variable,passing by reference, dont do it for superglobals like 
//$_POST.
//ONLY VARIABLES CAN BE PASSED BY REFERENCE, NOT NUMBERS OR STRINGS.
function disappearNum($abilValue,&$abilNum,&$usedNum)
{
if($_POST['strength']==$abilValue || $_POST['wisdom']==$abilValue || $_POST['charisma']==$abilValue || $_POST['dexterity']==$abilValue
|| $_POST['constitution']==$abilValue || $_POST['intelligence']==$abilValue)
{
$abilNum=''; 
$usedNum=true;
}
}
/////////////////////////////////////////
disappearNum(16,$sixteen,$sixteenUsed);//passing arguments into the function
disappearNum(14,$fourteen,$fourteenUsed);
disappearNum(13,$thirteen,$thirteenUsed);
disappearNum(12,$twelve,$twelveUsed);
disappearNum(11,$eleven,$elevenUsed);
disappearNum(10,$ten,$tenUsed);
//
//WE ARE GOING TO MAKE THE BELOW INTO A FUNCTION BY COMPARING THE COPIES, NOTING WHAT
//IS DIFFERENT, AND MAKING THOSE OUR FUNCTION PARAMETERS, THEN WE CALL THE FUNCTION
//AND PASS THE VALUES IN, UNLESS THE VARIABLES ARE SUPERGLOBALS, WE PUT A & BEFORE 
//THE DOLLAR SIGN IN OUR PARAMETER.


//if 16 already used from form, echo out nothing instead of '16' at the top of page.
//then make the number Used equal to true so we can use it later

/*
if($_POST['strength']==16 || $_POST['wisdom']==16 || $_POST['charisma']==16 || $_POST['dexterity']==16
|| $_POST['constitution']==16 || $_POST['intelligence']==16)
{
$sixteen=''; 
$sixteenUsed=true;
}

if($_POST['strength']==14 || $_POST['wisdom']==14 || $_POST['charisma']==14 || $_POST['dexterity']==14
|| $_POST['constitution']==14 || $_POST['intelligence']==14)
{
$fourteen=''; 
$fourteenUsed=true;
}
*/

//ONLY VARIABLES CAN BE PASSED BY REFERENCE NOT NUMBERS OR STRINGS.
////////////////////////////////////////////////////////////////////////////////////
function assignAbility(&$postAbil,&$playerAbil,$ability)
{
if(!empty($_POST[$postAbil]))
{
	if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
	{
		return 'Sorry you have already used this number.';
	}
	elseif($_POST[$postAbil]==16 || $_POST[$postAbil]==14 || $_POST[$postAbil]==13
	|| $_POST[$postAbil]==12 ||$_POST[$postAbil]==11 || $_POST[$postAbil]==10)
	{
		$_SESSION[$playerAbil]=$_POST['strength'];
		$assignMessage='You have assigned '.$_SESSION[$playerAbil].' to '.$ability;
	}
	else 
	{
		return 'please enter a correct number.';
	}

	return ''; //so we dont get an error.


}
}
assignAbility($strength,$playerStrength,'Strength'); // passing in the arguments.
assignAbility($wisdom,$playerWisdom,'Wisdom'); 
assignAbility($dexterity,$playerDexterity,'Dexterity'); 
assignAbility($intelligence,$playerIntelligence,'Intelligence'); 
assignAbility($charisma,$playerCharisma,'Charisma'); 
assignAbility($contitution,$playerConstitution,'constitution'); 

$usedMessage=assignAbility();
$assignMessage=assignAbility();
$error=assignAbility();  //make the return values echo out via these variables

//AGAIN, WE ARE GOING TO USE THE BELOW TWO COPIES, NOTE THE DIFFERENCES, MAKE THOSE 
//DIFFERENCES THE FUNCTION PARAMETERS, THEN PASS THE ARGUMENTS IN THE FUNCTION CALL.
//if they've already assigned this point, say sorry message, otherwise, assign point.
//we copy the large copy into the function and then add the parameters where the 
//specific names were.

/*if(!empty($_POST['strength']))
{
if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
{
	$usedMessage='Sorry you have already used this number.';
}
elseif($_POST['strength']==16 || $_POST['strength']==14 || $_POST['strength']==13
|| $_POST['strength']==12 ||$_POST['strength']==11 || $_POST['strength']==10)
{
	$_SESSION['playerStrength']=$_POST['strength'];
	$assignMessage='You have assigned '.$_SESSION['playerStrength'].' to Strength';
}
else 
{
	$error="please enter a correct number.";
}
}
if(!empty($_POST['wisdom']))
{
if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
{
	$usedMessage='Sorry you have already used this number.';
}
elseif($_POST['wisdom']==16 || $_POST['wisdom']==14 || $_POST['wisdom']==13
|| $_POST['wisdom']==12 ||$_POST['wisdom']==11 || $_POST['wisdom']==10)
{
	$_SESSION['playerWisdom']=$_POST['wisdom'];
	$assignMessage='You have assigned '.$_SESSION['playerWisdom'].' to Wisdom';
}
else 
{
	$error="please enter a correct number.";
}
}


*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Dereks Dragon Game</title>
<style type="text/css">
table {
width: 30%;
background-color:#CCCCCC;
border: 1px white solid;
}
</style>

</head>
<body>
<h3 align="center"> Welcome to Derek's Dragon Games</h3>
<br /><br /><p align='center'> <a href="choose_class.php">Go back to Class choose menu</a></p><br /><br />
<p align="center">Please assign the following ability points to your Abilities for your <?php echo "<strong>".$_SESSION['race']." ".$_SESSION['class']."</strong>.";?><br /><br /></p>
<p align="center"><strong><?php echo $sixteen.", ".$fourteen .", ". $thirteen.", ".$twelve.", ".$eleven.", ".$ten.". ";?></strong></p> 

<strong>Abilities:</strong><br /><br />
<?php echo $assignMessage;?>
<?php echo $usedMessage;?>
<?php echo $error;?>
<table><tr><td><strong>Strength (Str):</strong> measures your character’s physical
power. It’s important for most characters who fight
hand-to-hand. Clerics, fighters, paladins, rangers, and warlords have powers based on Strength.</td></tr>
</table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Strength:</strong><input type="text"  size="10" maxlength="2" name="strength"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Constitution: (Con)</strong> represents your character’s
health, stamina, and vital force. All characters benefit from a high Constitution score. Many warlock powers are based on Constitution.</td></tr></table><table> 
<tr><td><form action="ability_points.php" method="post"><strong>Constitution:</strong><input type="text" size="10" maxlength="2" name="contitution"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Dexterity:</strong>measures hand-eye coordination,
agility, reflexes, and balance. Many ranger and rogue powers are based on
Dexterity.</td></tr>
</table><table> 
<tr><td><form action="ability_points.php" method="post"><strong>Dexterity:</strong><input type="text"   size="10" maxlength="2"  name="dexterity" > <input type="submit"  value="Assign Points"/> </form></td></tr> 
</table><br /><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Intelligence (Int):</strong> Intelligence (Int) describes how well your character
learns and reasons. Wizard powers are based on Intelligence.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Intelligence:</strong><input type="text" size="10" maxlength="2" name="intelligence"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<br /> 
<?php echo $usedMessage;?>
<table><tr><td><strong>Wisdom (Wis):</strong> measures your common sense, perception,
self-discipline, and empathy. You use your Wisdom score to notice details, sense danger, and get a
read on other people.Many cleric powers are based on Wisdom.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Wisdom:</strong><input type="text"  size="10" maxlength="2" name="wisdom" > <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br /><br /> 
<?php echo $usedMessage;?>
<table><tr><td><strong>Charisma (Cha):</strong> measures your force of personality,
persuasiveness, and leadership.Many paladin and warlock powers are based on
Charisma.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Charisma:</strong><input type="text" size="10" maxlength="2" name="charisma"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br /><br /> 
<table><tr><td><form action="ability_points.php" method="post"><strong><input type="submit" value="Reset abilities" name="reset" /></form></form></td></tr>
<br /> 
</table>
</body>
</html>

 


Ok I fixed all the errors, here is the final code. Note: it doesn't work. LOL! But at least the errors are gone. Thanks for the advice. Derek

 

<?php
session_start();

// permanent character ability points assigned from form into these session vars
$_SESSION['playerStrength']='';
$_SESSION['playerWisdom']='';
$_SESSION['playerCharisma']='';
$_SESSION['playerConstitution']='';
$_SESSION['playerIntelligence']='';
$_SESSION['playerDexterity']='';

///variables to say that the number has already been used
$sixteenUsed='';
$fourteenUsed='';
$thirteenUsed='';
$twelveUsed='';
$elevenUsed='';
$tenUsed='';
//////////////////////////
$playerStrength='';
$playerWisdom='';
$playerCharisma='';
$playerIntelligence='';
$playerDexterity='';
$playerConstitution='';

$assignMessage='';
$error='';
$usedMessage='';

//ability points to disappear after used

$sixteen=16;
$fourteen=14;
$thirteen=13;
$twelve=12;
$eleven=11;
$ten=10;

///the following prevents this error
//Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 65
$_POST['reset']='';
$_POST['strength']='';
$_POST['wisdom']='';
$_POST['charisma']='';
$_POST['constitution']='';
$_POST['intelligence']='';
$_POST['dexterity']='';
/////////////////////////////////////////////////////////////////////////////////////
echo "<pre>".print_r($_POST, 1)."</pre>";


///////////////////////////////reset the points//////////////////////
if($_POST['reset'])
{
$_SESSION['playerWisdom']='';
$_SESSION['playerConstitution']='';
$_SESSION['playerStrength']='';
$_SESSION['playerCharisma']='';
$_SESSION['playerDexterity']='';
$_SESSION['playerIntelligence']='';

}
///////////////////////////////////////////////////////////////////////

//if 16 already used from form, echo out nothing instead of '16' at the top of page.
//then make the number Used equal to true so we can use it later this function has & 
//in front of the variable,passing by reference, dont do it for superglobals like 
//$_POST.
//ONLY VARIABLES CAN BE PASSED BY REFERENCE, NOT NUMBERS OR STRINGS.
function disappearNum($abilValue,&$abilNum,&$usedNum)
{
if($_POST['strength']==$abilValue || $_POST['wisdom']==$abilValue || $_POST['charisma']==$abilValue || $_POST['dexterity']==$abilValue
|| $_POST['constitution']==$abilValue || $_POST['intelligence']==$abilValue)
{
$abilNum=''; 
$usedNum=true;
}
}
/////////////////////////////////////////
disappearNum(16,$sixteen,$sixteenUsed);//passing arguments into the function
disappearNum(14,$fourteen,$fourteenUsed);
disappearNum(13,$thirteen,$thirteenUsed);
disappearNum(12,$twelve,$twelveUsed);
disappearNum(11,$eleven,$elevenUsed);
disappearNum(10,$ten,$tenUsed);
//
//WE ARE GOING TO MAKE THE BELOW INTO A FUNCTION BY COMPARING THE COPIES, NOTING WHAT
//IS DIFFERENT, AND MAKING THOSE OUR FUNCTION PARAMETERS, THEN WE CALL THE FUNCTION
//AND PASS THE VALUES IN, UNLESS THE VARIABLES ARE SUPERGLOBALS, WE PUT A & BEFORE 
//THE DOLLAR SIGN IN OUR PARAMETER.


//if 16 already used from form, echo out nothing instead of '16' at the top of page.
//then make the number Used equal to true so we can use it later

/*
if($_POST['strength']==16 || $_POST['wisdom']==16 || $_POST['charisma']==16 || $_POST['dexterity']==16
|| $_POST['constitution']==16 || $_POST['intelligence']==16)
{
$sixteen=''; 
$sixteenUsed=true;
}

if($_POST['strength']==14 || $_POST['wisdom']==14 || $_POST['charisma']==14 || $_POST['dexterity']==14
|| $_POST['constitution']==14 || $_POST['intelligence']==14)
{
$fourteen=''; 
$fourteenUsed=true;
}
*/

//ONLY VARIABLES CAN BE PASSED BY REFERENCE NOT NUMBERS OR STRINGS.
////////////////////////////////////////////////////////////////////////////////////
function assignAbility(&$postAbil,&$playerAbil,$ability)
{
if(!empty($_POST[$postAbil]))
{
	if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
	{
		$usedMessage='Sorry you have already used this number.';
	}
	elseif($_POST[$postAbil]==16 || $_POST[$postAbil]==14 || $_POST[$postAbil]==13
	|| $_POST[$postAbil]==12 ||$_POST[$postAbil]==11 || $_POST[$postAbil]==10)
	{
		$_SESSION[$playerAbil]=$_POST['strength'];
		$assignMessage='You have assigned '.$_SESSION[$playerAbil].' to '.$ability;
	}
	else 
	{
		$error='please enter a correct number.';
	}

	return ''; //so we dont get an error.


}
}
assignAbility($strength,$playerStrength,'Strength'); // passing in the arguments.
assignAbility($wisdom,$playerWisdom,'Wisdom'); 
assignAbility($dexterity,$playerDexterity,'Dexterity'); 
assignAbility($intelligence,$playerIntelligence,'Intelligence'); 
assignAbility($charisma,$playerCharisma,'Charisma'); 
assignAbility($contitution,$playerConstitution,'constitution'); 



//AGAIN, WE ARE GOING TO USE THE BELOW TWO COPIES, NOTE THE DIFFERENCES, MAKE THOSE 
//DIFFERENCES THE FUNCTION PARAMETERS, THEN PASS THE ARGUMENTS IN THE FUNCTION CALL.
//if they've already assigned this point, say sorry message, otherwise, assign point.
//we copy the large copy into the function and then add the parameters where the 
//specific names were.

/*if(!empty($_POST['strength']))
{
if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
{
	$usedMessage='Sorry you have already used this number.';
}
elseif($_POST['strength']==16 || $_POST['strength']==14 || $_POST['strength']==13
|| $_POST['strength']==12 ||$_POST['strength']==11 || $_POST['strength']==10)
{
	$_SESSION['playerStrength']=$_POST['strength'];
	$assignMessage='You have assigned '.$_SESSION['playerStrength'].' to Strength';
}
else 
{
	$error="please enter a correct number.";
}
}
if(!empty($_POST['wisdom']))
{
if($tenUsed==true || $elevenUsed==true || $twelveUsed==true || $thirteenUsed==true || $fourteenUsed==true || $sixteenUsed==true)
{
	$usedMessage='Sorry you have already used this number.';
}
elseif($_POST['wisdom']==16 || $_POST['wisdom']==14 || $_POST['wisdom']==13
|| $_POST['wisdom']==12 ||$_POST['wisdom']==11 || $_POST['wisdom']==10)
{
	$_SESSION['playerWisdom']=$_POST['wisdom'];
	$assignMessage='You have assigned '.$_SESSION['playerWisdom'].' to Wisdom';
}
else 
{
	$error="please enter a correct number.";
}
}


*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Dereks Dragon Game</title>
<style type="text/css">
table {
width: 30%;
background-color:#CCCCCC;
border: 1px white solid;
}
</style>

</head>
<body>
<h3 align="center"> Welcome to Derek's Dragon Games</h3>
<br /><br /><p align='center'> <a href="choose_class.php">Go back to Class choose menu</a></p><br /><br />
<p align="center">Please assign the following ability points to your Abilities for your <?php echo "<strong>".$_SESSION['race']." ".$_SESSION['class']."</strong>.";?><br /><br /></p>
<p align="center"><strong><?php echo $sixteen.", ".$fourteen .", ". $thirteen.", ".$twelve.", ".$eleven.", ".$ten.". ";?></strong></p> 

<strong>Abilities:</strong><br /><br />
<?php echo $assignMessage;?>
<?php echo $usedMessage;?>
<?php echo $error;?>
<table><tr><td><strong>Strength (Str):</strong> measures your character’s physical
power. It’s important for most characters who fight
hand-to-hand. Clerics, fighters, paladins, rangers, and warlords have powers based on Strength.</td></tr>
</table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Strength:</strong><input type="text"  size="10" maxlength="2" name="strength"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Constitution: (Con)</strong> represents your character’s
health, stamina, and vital force. All characters benefit from a high Constitution score. Many warlock powers are based on Constitution.</td></tr></table><table> 
<tr><td><form action="ability_points.php" method="post"><strong>Constitution:</strong><input type="text" size="10" maxlength="2" name="contitution"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Dexterity:</strong>measures hand-eye coordination,
agility, reflexes, and balance. Many ranger and rogue powers are based on
Dexterity.</td></tr>
</table><table> 
<tr><td><form action="ability_points.php" method="post"><strong>Dexterity:</strong><input type="text"   size="10" maxlength="2"  name="dexterity" > <input type="submit"  value="Assign Points"/> </form></td></tr> 
</table><br /><br />
<?php echo $usedMessage;?>
<table><tr><td><strong>Intelligence (Int):</strong> Intelligence (Int) describes how well your character
learns and reasons. Wizard powers are based on Intelligence.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Intelligence:</strong><input type="text" size="10" maxlength="2" name="intelligence"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br />
<br /> 
<?php echo $usedMessage;?>
<table><tr><td><strong>Wisdom (Wis):</strong> measures your common sense, perception,
self-discipline, and empathy. You use your Wisdom score to notice details, sense danger, and get a
read on other people.Many cleric powers are based on Wisdom.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Wisdom:</strong><input type="text"  size="10" maxlength="2" name="wisdom" > <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br /><br /> 
<?php echo $usedMessage;?>
<table><tr><td><strong>Charisma (Cha):</strong> measures your force of personality,
persuasiveness, and leadership.Many paladin and warlock powers are based on
Charisma.</td></tr></table>
<table> 
<tr><td><form action="ability_points.php" method="post"><strong>Charisma:</strong><input type="text" size="10" maxlength="2" name="charisma"> <input type="submit"  value="Assign Points" /> </form></td></tr> 
</table><br /><br /> 
<table><tr><td><form action="ability_points.php" method="post"><strong><input type="submit" value="Reset abilities" name="reset" /></form></form></td></tr>
<br /> 
</table>
</body>
</html>

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.