silverglade Posted July 23, 2010 Share Posted July 23, 2010 Hi I am getting error messages like this. A lot of them. Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 45 Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 45 Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 45 and the $_POST array is not being set from my form. Any help greatly appreciated. Here is my code. Thanks. 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=''; //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>"; //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'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='16') { $sixteen=''; $sixteenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='14') { $fourteen=''; $fourteenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='13') { $thirteen=''; $thirteenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='12') { $twelve=''; $twelveUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='11') { $eleven=''; $elevenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='10') { $ten=''; $tenUsed=true; } //////////////////////////////////////////////////////////////////////////////////// //if they've already assigned this point, say sorry message, otherwise, assign point. if(!empty($_POST['strength'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerStrength']=$_POST['strength']; $assignMessage='You have assigned '.$_SESSION['playerStrength'].' to Strength'; } } if(!empty($_POST['wisdom'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerWisdom']=$_POST['wisdom']; $assignMessage='You have assigned '.$_SESSION['playerWisdom'].' to Wisdom'; } } if(!empty($_POST['charisma'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerCharisma']=$_POST['charisma']; $assignMessage='You have assigned '.$_SESSION['playerCharisma'].' to Charisma'; } } if(!empty($_POST['constitution'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerConstitution']=$_POST['constitution']; $assignMessage='You have assigned '.$_SESSION['playerConstitution'].' to Constitution'; } } if(!empty($_POST['intelligence'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerIntelligence']=$_POST['intelligence']; $assignMessage='You have assigned '.$_SESSION['playerIntelligence'].' to Intelligence'; } } if(!empty($_POST['dexterity'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerDexerity']=$_POST['strength']; $assignMessage='You have assigned '.$_SESSION['playerDexterity'].' to Dexterity'; } } ?> <!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;?> <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><strong>Strength:</strong><input type="text" action="ability_points.php" size="10" maxlength="2" method="post"> <input type="submit" value="Assign Points" name="strength"/> </form></td></tr> </table><br /> <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><strong>Constitution:</strong><input type="text" action="ability_points.php" size="10" maxlength="2" method="post"> <input type="submit" value="Assign Points" name="contitution"/> </form></td></tr> </table><br /> <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><strong>Dexterity:</strong><input type="text" action="ability_points.php" size="10" maxlength="2" method="post"> <input type="submit" value="Assign Points" name="dexterity"/> </form></td></tr> </table><br /><br /> <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><strong>Intelligence:</strong><input type="text" action="ability_points.php" size="10" maxlength="2" method="post"> <input type="submit" value="Assign Points" name="intelligence"/> </form></td></tr> </table><br /> <br /> <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><strong>Wisdom:</strong><input type="text" action="ability_points.php" size="10" maxlength="2" method="post"> <input type="submit" value="Assign Points" name="wisdom"/> </form></td></tr> </table><br /><br /> <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><strong>Charisma:</strong><input type="text" action="ability_points.php" size="10" maxlength="2" method="post"> <input type="submit" value="Assign Points" name="charisma"/> </form></td></tr> </table><br /><br /> <br /> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/208678-getting-undefined-error-message-and-_post-array-not-filling/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 23, 2010 Share Posted July 23, 2010 The method=".." and action=".." attributes go into the <form ....> tag. They don't go into an <input ...> tag. Quote Link to comment https://forums.phpfreaks.com/topic/208678-getting-undefined-error-message-and-_post-array-not-filling/#findComment-1090179 Share on other sites More sharing options...
silverglade Posted July 23, 2010 Author Share Posted July 23, 2010 Great thank you again. I still get the errors upon loading the page. Notice: Undefined index: strength in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 44 Notice: Undefined index: wisdom in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 44 Notice: Undefined index: charisma in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 44 Notice: Undefined index: dexterity in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 44 Notice: Undefined index: constitution in C:\wamp\www\dragon_game\dragon_game\ability_points.php on line 45 Here is the page with the form tags fixed. Any more help greatly appreciated. thanks. 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=''; //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>"; //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'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='16') { $sixteen=''; $sixteenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='14') { $fourteen=''; $fourteenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='13') { $thirteen=''; $thirteenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='12') { $twelve=''; $twelveUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='11') { $eleven=''; $elevenUsed=true; } if($_POST['strength'] || $_POST['wisdom'] || $_POST['charisma'] || $_POST['dexterity'] || $_POST['constitution'] || $_POST['intelligence']=='10') { $ten=''; $tenUsed=true; } //////////////////////////////////////////////////////////////////////////////////// //if they've already assigned this point, say sorry message, otherwise, assign point. if(!empty($_POST['strength'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerStrength']=$_POST['strength']; $assignMessage='You have assigned '.$_SESSION['playerStrength'].' to Strength'; } } if(!empty($_POST['wisdom'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerWisdom']=$_POST['wisdom']; $assignMessage='You have assigned '.$_SESSION['playerWisdom'].' to Wisdom'; } } if(!empty($_POST['charisma'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerCharisma']=$_POST['charisma']; $assignMessage='You have assigned '.$_SESSION['playerCharisma'].' to Charisma'; } } if(!empty($_POST['constitution'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerConstitution']=$_POST['constitution']; $assignMessage='You have assigned '.$_SESSION['playerConstitution'].' to Constitution'; } } if(!empty($_POST['intelligence'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerIntelligence']=$_POST['intelligence']; $assignMessage='You have assigned '.$_SESSION['playerIntelligence'].' to Intelligence'; } } if(!empty($_POST['dexterity'])) { if($tenUsed || $elevenUsed || $twelveUsed || $thirteenUsed || $fourteenUsed || $sixteenUsed) { $usedMessage='Sorry you have already used this number.'; } else { $_SESSION['playerDexerity']=$_POST['strength']; $assignMessage='You have assigned '.$_SESSION['playerDexterity'].' to Dexterity'; } } ?> <!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;?> <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" > <input type="submit" value="Assign Points" name="strength"/> </form></td></tr> </table><br /> <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" > <input type="submit" value="Assign Points" name="contitution"/> </form></td></tr> </table><br /> <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" > <input type="submit" value="Assign Points" name="dexterity"/> </form></td></tr> </table><br /><br /> <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""> <input type="submit" value="Assign Points" name="intelligence"/> </form></td></tr> </table><br /> <br /> <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" > <input type="submit" value="Assign Points" name="wisdom"/> </form></td></tr> </table><br /><br /> <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" > <input type="submit" value="Assign Points" name="charisma"/> </form></td></tr> </table><br /><br /> <br /> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/208678-getting-undefined-error-message-and-_post-array-not-filling/#findComment-1090193 Share on other sites More sharing options...
PFMaBiSmAd Posted July 23, 2010 Share Posted July 23, 2010 Your <input ... > tags need name="..." attributes that match the $_POST['...'] in order to set the post variables. These are some pretty basic concepts of forms. You did read through a tutorial before you attempted this? Quote Link to comment https://forums.phpfreaks.com/topic/208678-getting-undefined-error-message-and-_post-array-not-filling/#findComment-1090203 Share on other sites More sharing options...
silverglade Posted July 23, 2010 Author Share Posted July 23, 2010 Thank you . Yes I probably should read up more on w3schools. Thanks for helping me again! Derek Quote Link to comment https://forums.phpfreaks.com/topic/208678-getting-undefined-error-message-and-_post-array-not-filling/#findComment-1090211 Share on other sites More sharing options...
Pikachu2000 Posted July 23, 2010 Share Posted July 23, 2010 It's misspelled in the form field name attribute. <input type="submit" value="Assign Points" name="contitution"/>. Quote Link to comment https://forums.phpfreaks.com/topic/208678-getting-undefined-error-message-and-_post-array-not-filling/#findComment-1090213 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.