stutego Posted November 13, 2012 Share Posted November 13, 2012 (edited) please i have an error message as viz(Notice: Undefined variable: select in C:\xampp\htdocs\interest.php) running this code <?php //lets select options from a dropdown list using php functions $month = array("jan" => "Jan", "feb" => "Feb", "mar" => "Mar", "apr" => "Apr", "may" => "May", "jun" => "Jun", "jul" => "Jul", "aug" => "Aug", "sep" => "Sep", "oct" => "Oct", "nov" => "Nov", "dec" => "Dec"); $default = "jan"; $select = generate_menu("month", $month, $default); function generate_menu($name, $month, $default="") { $select .= "<SELECT NAME=\"$name\">"; <<<<------- this is where the error is located foreach($month as $value => $label) { $select .= "<OPTION "; if ($value == $default) $select .= "SELECTED "; $select .= "VALUE=\"$value\">$label</OPTION>"; } $select .= "</SELECT>"; return($select); } ?> <FORM ACTION="month.php" METHOD=POST> <?php print $select;?> <INPUT TYPE=SUBMIT VALUE="Continue"> </FORM> Edited November 13, 2012 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/ Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 Please use the code tags and indent your code. Within your function, $select is not defined. You probably want to just create it the first time, rather than trying to append to it. $select = "<select... rather than $select .= "<select... Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392046 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 @Jessica please i've tried it out, but only got just the (contine) button please help me out my still a newbie to php Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392050 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 Post your updated code. In code tags. Use the plain text editor if you need to. If you changed it EVERYWHERE and not just the first time you try to use that variable, that won't work. Think about it. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392052 Share on other sites More sharing options...
Barand Posted November 13, 2012 Share Posted November 13, 2012 Your function needs to return $select; Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392055 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 (edited) the updated code took off the error but wasnt giving me the dropdown list i coded this is the updated code <?php //lets select options from a dropdown list using php functions $month = array("jan" => "Jan", "feb" => "Feb", "mar" => "Mar", "apr" => "Apr", "may" => "May", "jun" => "Jun", "jul" => "Jul", "aug" => "Aug", "sep" => "Sep", "oct" => "Oct", "nov" => "Nov", "dec" => "Dec"); $default = "jan"; $select = generate_menu("month", $month, $default); function generate_menu($name, $month, $default="") { $select= "<SELECT NAME=\"$name\">"; foreach($month as $value => $label) { $select= "<OPTION "; if ($value == $default) $select= "SELECTED "; $select= "VALUE=\"$value\">$label</OPTION>"; } $select= "</SELECT>"; return($select); } ?> <FORM ACTION="month.php" METHOD=POST> <?php print $select;?> <INPUT TYPE=SUBMIT VALUE="Continue"> </FORM> and more over the editor am using is notepad+++ please help me out i've been sick of this code for sum days now Edited November 13, 2012 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392056 Share on other sites More sharing options...
AyKay47 Posted November 13, 2012 Share Posted November 13, 2012 (edited) Using the advice that Jesi initially gave you, and with a little cleanup added, this code should work for you: $month = array("jan" => "Jan", "feb" => "Feb", "mar" => "Mar", "apr" => "Apr", "may" => "May", "jun" => "Jun", "jul" => "Jul", "aug" => "Aug", "sep" => "Sep", "oct" => "Oct", "nov" => "Nov", "dec" => "Dec"); $default = "jan"; $menu = generate_menu("month", $month, $default); function generate_menu($name, $month, $default="") { $select = "<select name='$name'>"; foreach($month as $value => $label) { $select .= "<option "; if ($value == $default) $select .= "selected='selected' "; $select .= "value='$value'>$label</option>"; } $select .= "</select>"; return $select; } echo $menu; Also, the function returned $select from the initial post. Edited November 13, 2012 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392057 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 @ Your function needs to return $select; return $select; is there Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392058 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 Post your updated code. In code tags. Use the plain text editor if you need to. If you changed it EVERYWHERE and not just the first time you try to use that variable, that won't work. Think about it. You did like maybe 1/5th of what this post says. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392065 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 much tanx to Jessica, Aykay47 & Barand 4 helping me out with my prob i used Aykay47's anwser and it worked out well.... much tanx 2 Jessica for ur's 2...... like i've said before am new to php and programming environment wish to be creative using php Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392066 Share on other sites More sharing options...
Barand Posted November 13, 2012 Share Posted November 13, 2012 @ return $select; is there Sorry, I mis-counted the }s Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392067 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 @ You did like maybe 1/5th of what this post says. what did u mean by saying i did just 1/5th and can u explain the remaining 1ce i did'nt do Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392068 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 You didn't post using the code tags. You apparently didn't read the entire second sentence, because it explains what's wrong with your code. I'm guessing you don't understand what .= and = do. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392069 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 You didn't post using the code tags. You apparently didn't read the entire second sentence, because it explains what's wrong with your code. I'm guessing you don't understand what .= and = do. haha i forgot adding the tag tanx a lot Jessy wil love u helping out next time on any prob Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392071 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 but please @jessy what are diff btw .= & = and what are their functions to the code Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392072 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 Hey stupido. Look it up in the manual. Give it like, 5 minutes of your own time and try to learn it. Also this isn't twitter, and my name is Jessica. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392074 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 k m sorry @Jessica but dat ws'nt inclusive in the ebook am using, am using oreilly's php ebook Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392077 Share on other sites More sharing options...
KevinM1 Posted November 13, 2012 Share Posted November 13, 2012 Like Jessica stated, this forum isn't like Twitter. Writing in shortened internet lingo only makes it harder for us to understand what you're saying, which ultimately makes it harder for us to help you. We don't have a 140 character limit, so slow down, write complete sentences, and be as clear and concise as you can about your problem. When posting code, place it within tags. That will format it and apply syntax highlighting so we can more easily see what's going on. In short, the easier it is for us to understand you and your problem, the faster it will be addressed. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392079 Share on other sites More sharing options...
White_Lily Posted November 13, 2012 Share Posted November 13, 2012 As for what Jess said on like the first or second post she did - about the indenting - when you copy and paste code into the text editor, the text editior takes out all of the indenting thereby making it all just a plain list. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392081 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 As for what Jess said on like the first or second post she did - about the indenting - when you copy and paste code into the text editor, the text editior takes out all of the indenting thereby making it all just a plain list. Not if you use the plain text editor. function test(){ echo 'hello world'; } I c&p that from my text editor into the plain text here. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392083 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 ok kelvin tanx 4 that... Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392086 Share on other sites More sharing options...
stutego Posted November 13, 2012 Author Share Posted November 13, 2012 tanx to you all for helping out Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392088 Share on other sites More sharing options...
woot Posted November 13, 2012 Share Posted November 13, 2012 but please @jessy what are diff btw .= & = and what are their functions to the code You may have figured it out by now but replying to your question '=' means you're assigning a value to a variable. For example: $a = 5; //means your variable $a receives the value 5 When you use '.=' it will append a string to the value already contained in the variable like $a = "This is the first sentence."; $a .= " This is the second sentence."; After this your variable $a will contain the string "This is the first sentence. This is the second sentence.". I hope it's clear enough for you to understand. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392089 Share on other sites More sharing options...
AyKay47 Posted November 13, 2012 Share Posted November 13, 2012 stutego, this link will help you understand the concept of concatenation better. Quote Link to comment https://forums.phpfreaks.com/topic/270630-hi-am-new-to-this-forum-pls-i-will-like-someone-to-help-me-out-on-this/#findComment-1392097 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.