Jump to content

Hi Am New To This Forum Pls I Will Like Someone To Help Me Out On This


stutego

Recommended Posts

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 by Zane
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Zane
Link to comment
Share on other sites

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 by AyKay47
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.