Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

php variable


ghost's Avatar
0 0

Ok so I want the $many variable to have different values when the $number value is different.

switch($number)

{ case "1": echo "<br> <select><option name='grade1' value='4'>A</option> <option name='grade1' value='3'>B</option> <option name='grade1' value='2'>C</option> <option name='grade1' value='1'>D</option> <option name='grade1' value='0'>F</option> </select>";

	$many = &quot;1&quot;;

(this is just part of the code) After distinguishing this through each case- when $number = "2"; $many = "2"; and so on…. I go to the next page where I find that i cannot echo or use the $many variable it is simply zero…. Please help.


spyware's Avatar
Banned
0 0

Take some time to learn how to code in PHP, before you make a fool out of yourself. Please, learn.


ghost's Avatar
0 0

well i am and i just need help… what did i do wrong?


spyware's Avatar
Banned
0 0

darthchocobo wrote: well i am and i just need help… what did i do wrong?

Asking stupid questions (yes, there are stupid questions). Take your time to LEARN, asking us for help is not LEARNING, it's being STUPID.

Stop being stupid, start learning.


ghost's Avatar
0 0

I see quite a few problems and I don't even code in PHP: often

  1. What in the world are you trying to accomplish? Your code does not make sense in the lease bit.
  2. Why do you treat your integers as strings?
  3. You are missing the "break;" for your "case 1:" and your default case is missing.
  4. Why do all your options have the same name? It looks silly to have all the options display the same thing.
  5. Should't your options be outside the switch case function? I think you should then have the value passed to a variable.

Try w3schools.com and php.net also, Youtube has some PHP vids. Next, join a programming forum and proogread other people's code and see if you can spot errors in it. to me, the best way to learn is to debug other peopl's stuff.


ghost's Avatar
0 0
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Php Send Form&lt;/title&gt;
&lt;?php
$number=$_POST[&#39;grade1&#39;];
//This captures what you post
echo &quot;&lt;h6&gt;You submitted the value $number .&lt;/h6&gt;&quot;;
//You could just assign many to the value of number
//But if you just wanted to practice the switch-case then
    /* switch($number)
     {
             case 0:
             $many=0;
//Note the lack of quotes
             break;
//The break is necessary for preventing the switch-case from running
//into the next statement
             case 1:
             $many=1;
             break;
//etc, you can fill in the rest of the cases
             default:
             echo &quot;Error in processing request&quot;;
//the default case does not need a break
      }

OR
$many=$number
  */
/*Also note, professional programmers
strongly disapprove of nesting comments (putting one comment inside of another)
however, I just did it so that you could remove the multi-line comments and the excess code and still have the code work perfectly
The line ends here as you should be able to take
it up by yourself
 */
?&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&#39;&#39; method=&quot;POST&quot;&gt;
//Tells you that it will POST the value
//and submit the form to itself
&lt;select name=&#39;grade1&#39;&gt;
//The name option goes within the select tags
	&lt;option value=&#39;4&#39;&gt;A&lt;/option&gt;
	&lt;option value=&#39;3&#39;&gt;B&lt;/option&gt;
	&lt;option value=&#39;2&#39;&gt;C&lt;/option&gt;
	&lt;option value=&#39;1&#39;&gt;D&lt;/option&gt;
	&lt;option value=&#39;0&#39;&gt;F&lt;/option&gt;
&lt;/select&gt;
&lt;input type=&quot;submit&quot; value=&quot;Submit Form&quot;/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Note: I am only doing this to help you in the sense that you will compare the code and adjust for errors. Also, do not believe that people will always help you with your code. It's only that I'm nice and you're new here that I took the time to edit this. And I see you're already well acquainted with Spyware. Watch out, he eats newbies for breakfast!:o @Spyware, I disagree. He is trying to learn, however, he picked up some bad habits from wherever he was trying to learn so he needed us to tell us what is wrong.


Mr_Cheese's Avatar
0 1

darthchocobo wrote: I go to the next page where I find that i cannot echo or use the $many variable it is simply zero…. Please help.

well ofcourse you cant. if its the next page, then $many wont be defined will it. variables only work on the page they are defined.

if you want variables to be used between pages, use sessions, or GET variables.


ranma's Avatar
Member
0 0

It's like recording a message on my answering machine and wondering why Mr_Cheese's answering machine does not have the message. You never gave it the value. You can pass GET values like this: index.php?valuefromanotherpage=Ohyeah.