twilitegxa Posted June 29, 2009 Share Posted June 29, 2009 My php page is displaying two Undefined Index errors, but I'm not sure why. Can someone tell me why the error is displaying? Do I have the variables in the wrong place? Here is the code: <?php session_start(); //Access Tracking Snippet //set up static variables $page_title = "creationform.php"; $user_agent = getenv("HTTP_USER_AGENT"); $date_accessed = date("Y-m-d"); //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("smrpg", $conn) or die(mysql_error()); //create and issue query $sql = "insert into access_tracker values ('', '$page_title', '$user_agent', '$date_accessed')"; mysql_query($sql,$conn); $gender = $_POST['gender']; //Male or female? $status = $_POST['status']; //Hero or villain? if($status == "villain"){ //Since you're a villain, we just redirect here to the villain page header("Location: villain.php"); exit; }elseif($status == "hero"){ if($gender == "male"){ //You are a male hero! header("Location: knight.php"); exit; }elseif($gender == "female"){ //You are a female hero! header("Location: scout.php"); exit; } } ?> <title>Sailor Moon RPG - Character Creation - Step 2: Character Outline</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <h1>Step 2: Character Outline - Creation</h1> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <table> <tr> <td>Would you like to create a:</td><td><input type="radio" name="status" value="hero" /> Hero or a <input type="radio" name="status" value="villain" /> Villain</td></tr> <tr><td></td><td><input type="radio" name="gender" value="female" /> Female or <input type="radio" name="gender" value="male" /> Male</td></tr></table><br /> <center><input type="submit" name="submit" value="Create Character" /> <input type="reset" name="reset" value="Reset" /></center> </form> </div> <?php include("bottomnav.php"); ?> <div id="main"> </div> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/164021-solved-undefined-index/ Share on other sites More sharing options...
MadTechie Posted June 29, 2009 Share Posted June 29, 2009 telling us the line does help but at a guess i would say these $gender = $_POST['gender']; //Male or female? $status = $_POST['status']; //Hero or villain? change to $gender = (!empty($_POST['gender']))?$_POST['gender']:""; //Male or female? $status = (!empty($_POST['status']))?$_POST['status']:""; //Hero or villain? Quote Link to comment https://forums.phpfreaks.com/topic/164021-solved-undefined-index/#findComment-865270 Share on other sites More sharing options...
twilitegxa Posted June 29, 2009 Author Share Posted June 29, 2009 I'm sorry! I didn't realize I hadn't told you the lines! That did seem to fix the problem, but now for some reason my page still has a bunch of empty space at the top. Can you help me eliminate the space? do you need to see the CSS? Quote Link to comment https://forums.phpfreaks.com/topic/164021-solved-undefined-index/#findComment-865272 Share on other sites More sharing options...
MadTechie Posted June 29, 2009 Share Posted June 29, 2009 Can you post the URL, as its easier for me to look their (and a can get the CSS + HTML from their) Quote Link to comment https://forums.phpfreaks.com/topic/164021-solved-undefined-index/#findComment-865273 Share on other sites More sharing options...
twilitegxa Posted June 29, 2009 Author Share Posted June 29, 2009 Well, I don't have it on my server yet; just have it on my locahost, but I did adjust the top margin and now the space it eliminated! Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/164021-solved-undefined-index/#findComment-865276 Share on other sites More sharing options...
MadTechie Posted June 29, 2009 Share Posted June 29, 2009 Welcome kinda lucky I suck as page design Quote Link to comment https://forums.phpfreaks.com/topic/164021-solved-undefined-index/#findComment-865277 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.