php variable
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 = "1";
(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.
I see quite a few problems and I don't even code in PHP: often
- What in the world are you trying to accomplish? Your code does not make sense in the lease bit.
- Why do you treat your integers as strings?
- You are missing the "break;" for your "case 1:" and your default case is missing.
- Why do all your options have the same name? It looks silly to have all the options display the same thing.
- 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.
<html>
<head>
<title>Php Send Form</title>
<?php
$number=$_POST['grade1'];
//This captures what you post
echo "<h6>You submitted the value $number .</h6>";
//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 "Error in processing request";
//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
*/
?>
</head>
<body>
<form action='' method="POST">
//Tells you that it will POST the value
//and submit the form to itself
<select name='grade1'>
//The name option goes within the select tags
<option value='4'>A</option>
<option value='3'>B</option>
<option value='2'>C</option>
<option value='1'>D</option>
<option value='0'>F</option>
</select>
<input type="submit" value="Submit Form"/>
</form>
</body>
</html>
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.
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.