Jump to content

Simple php, whats wrong with this code?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
pathtotake

pathtotake

    Newbie

  • Members
  • PipPip
  • 13 posts
$val = $POST["name"];

if($_POST['mydropdown'] == 'a'){

switch($val){
case ($val>=70):
echo "13 - 15 First Class Honours";
break;
case ($val>=60):
echo "10 - 12 Upper Second Class Honours";
break;
case ($val>=50):
echo "7 - 9 Lower Second Class Honours";
break;
case ($val>=40):
echo "4 - 6 Third Class Honours";
break;
default:
echo "0 - 3 Fail";
}
}

I also tried this way:

$val = $POST["name"];



if (isset($_POST['submit']))

{
//echo $_POST["name"];

}
switch ($_POST['mydropdown']){
case 'a':
   if (( $val >=70) and ($val <=100)) {
    echo "13 - 15 First Class Honours";
}
else if (( $val >=60)and($val <= 69))
{
    echo "10 - 12 Upper Second Class Honours";
}
//echo $_POST["name"];
else if (( $val >=50)and($val <= 59))
{
    echo "7 - 9 Lower Second Class Honours";
}
else if (( $val >=40)and($val <= 49))
{
    echo "4 - 6 Third Class Honours";
}
else if (( $val >=0)and($val <= 39))
{
    echo "0 - 3 Fail";
}

break;
case 'b':
echo 'You chose B';
break;
case 'c':
echo 'You chose C';
break;
}

?>


Ive asked about it on yahoo answers and thats where I got the first version of code that I posted, but that didnt work either, the first version of code outputs only "first class honours" and the second version only outputs "fail" no matter what I enter in the textfield

Any help?

#2
pathtotake

pathtotake

    Newbie

  • Members
  • PipPip
  • 13 posts
It seems I missed out the underscore at $_post

But I have a question.

How do I open a php page if something happens for example, if a > b then open something.php

Chars

#3
pathtotake

pathtotake

    Newbie

  • Members
  • PipPip
  • 13 posts
Also, anyone know how to extract specific characters in a text field?
e.g.
if theres a number in a field extract it, and if theres a + in a field extract it.

#4
johnny123

johnny123

    Newbie

  • Members
  • PipPip
  • 10 posts
Hi pathtotake, if I understand it correctly. Your code is correct and you should be executing it when the form is submitting. If you are already submitting the form, try doing <?php print_r($form); ?> on top of your code and tell me what your output is once you submit the form.

#5
johnny123

johnny123

    Newbie

  • Members
  • PipPip
  • 10 posts
In response to your second question, do your redirect using header() function.

#6
johnny123

johnny123

    Newbie

  • Members
  • PipPip
  • 10 posts
In response to your third question, use Php strip_tags() function.

#7
pathtotake

pathtotake

    Newbie

  • Members
  • PipPip
  • 13 posts

johnny123 said:

In response to your third question, use Php strip_tags() function.
Thanks for your help.

Would you know anything about searching through mysql?

#8
johnny123

johnny123

    Newbie

  • Members
  • PipPip
  • 10 posts
You can use mysql "like" in your query to search for a particular text.

#9
pathtotake

pathtotake

    Newbie

  • Members
  • PipPip
  • 13 posts

johnny123 said:

You can use mysql "like" in your query to search for a particular text.

This doesn't help.

#10
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts

pathtotake said:

This doesn't help.

Probably because you being rather vague. Expand on what you mean by 'searching through mysql'.

#11
SoN9ne

SoN9ne

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
I see someone already pointed out the $_POST issue...
You should really check for isset on these... check you log

mysql LIKE '%search%' may be useful, I am assuming you are not aware of the %.
"Life would be so much easier if we only had the source code."

#12
pathtotake

pathtotake

    Newbie

  • Members
  • PipPip
  • 13 posts

SoN9ne said:

I see someone already pointed out the $_POST issue...
You should really check for isset on these... check you log

mysql LIKE '%search%' may be useful, I am assuming you are not aware of the %.

Thanks guys but this wouldn't have helped. I solved these problems by reading tutorials which is what I should have done in the first place.

Saying things like "mysql LIKE '%search%' may be useful", will mean nothing to me, since I don't even know exactly what mysql even is (its a database! and scripting language? if so, how?).
I got a lot of it to work though.

Ive submitted what needs to be submitted now, so it's all good.