Jump to content

IF ELSE Help


cjlong

Recommended Posts

Hello,

 

I'm trying to create a form with a numerical input. Based on the numerical Input I was trying to get a response.

 

Basically a value is input within a form and I'm trying to create an if else statement to give me two outputs based on the number entered. I'm new to php and I'm trying to learn. Please help me. This is the code:

 

Form Value Code:

<body>

<div align="center">

<form action="labcrosscheck.php" method="post">

  <span class="style5">GGT Value:</span>

  <input type="text" name="ggtvalue" />

<input type="submit" />

</form>

</div>

</body>

 

 

Output File Code:

<body>

<?php

if ($ggtvalue=="<55")

  echo $_POST["Cardiovascular Disease is less likely"];

else

  echo $_POST["Cardiovascular Disease is suspect"];

?>

 

 

</body>

Link to comment
https://forums.phpfreaks.com/topic/218224-if-else-help/
Share on other sites

And the problem is... what? That you don't get any kind of message for anything you enter?

 

1. You're trying to use register_globals in your code, except it's disabled. Don't enable it. Just use $_POST["ggtvalue"] instead.

2. The two $_POST["Cardiovascular..."] things don't exist. $_POST is only for stuff that came in through a form with method=post and those two messages did not.

 

Making fixes for those two, as well as checking that the form was actually submitted (instead of assuming it was), you might end up with

if (isset($_POST["ggtvalue"])) { // check that the form was submitted
  if ($_POST["ggtvalue"]=="    echo "Cardiovascular Disease is less likely";
  else
    echo "Cardiovascular Disease is suspect";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/218224-if-else-help/#findComment-1132346
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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