Jump to content

Php validation


Laguna

Recommended Posts

Why is it not validating ??

 

<form id="form1" name="form1" method="post" action="DiagnosisSoup.php">
      <div align="center">Temeprature 
        <label>
        <input type="text" name="temp" />
        </label>
        <p>
          <label>
          <input type="checkbox" name="running_nose" value="checkbox" />
          Running nose</label>
        </p>
        <p>
          <label>
          <input type="submit" name="submitted" value="Submit" />
          </label>
        </p>
      </div>
    </form>

 

 

 

 

 

 

 

<?
//if the form is submitted, process user input
if (isset($_POST['submitted']))
{
//verify user input
$result = true;
if (is_numeric($_POST['temp']))
{
   echo "Temperature should be numeric";
   $ready = false;
  }
  //check as many conditions as you like

  if ($_POST['temp']>42 || $_POST['temp']<30)
{
   echo "You should be dead by now.";
   $ready = false;
  }

//if all's well, process data
if ($ready)
{
   if ($_POST['temp']>37.5 && isset($_POST['running_nose'])) echo "You probably have cold.";
}
else DrawForm(); //data wasn't validated, so draw the form once again
}
else //form isn't submitted yet, so draw the form
{
  DrawForm();
}

function DrawForm()
{
include'testdiagnosis.php';
} 
?>

 

can anyone help ??

 

Link to comment
https://forums.phpfreaks.com/topic/48647-php-validation/
Share on other sites

Change it to this and tell me what happens:

 

<form id="form1" name="form1" method="post" action="DiagnosisSoup.php">
      <div align="center">Temeprature 
        <label>
        <input type="text" name="temp" value="42"/>
        </label>
        <p>
          <label>
          <input type="checkbox" name="running_nose" value="checkbox" />
          Running nose</label>
        </p>
        <p>
          <label>
          <input type="submit" name="submitted" value="Submit" />
          </label>
        </p>
      </div>
    </form>

Link to comment
https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238217
Share on other sites

Change it to this and tell me what happens:

 

<form id="form1" name="form1" method="post" action="DiagnosisSoup.php">
      <div align="center">Temeprature 
        <label>
        <input type="text" name="temp" value="42"/>
        </label>
        <p>
          <label>
          <input type="checkbox" name="running_nose" value="checkbox" />
          Running nose</label>
        </p>
        <p>
          <label>
          <input type="submit" name="submitted" value="Submit" />
          </label>
        </p>
      </div>
    </form>

 

it still says temperature is numeric

 

Link to comment
https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238223
Share on other sites

post the DiagnosisSoup.php page code up please.

 

<?
//if the form is submitted, process user input
if (isset($_POST['submitted']))
{
//verify user input
$result = true;
if (is_numeric($_POST['temp']))
{
   echo "Temperature should be numeric";
   $ready = false;
  }
  //check as many conditions as you like

  if ($_POST['temp']>42 || $_POST['temp']<30)
{
   echo "You should be dead by now.";
   $ready = false;
  }

//if all's well, process data
if ($ready)
{
   if ($_POST['temp']>37.5 && isset($_POST['running_nose'])) echo "You probably have cold.";
}
else DrawForm(); //data wasn't validated, so draw the form once again
}
else //form isn't submitted yet, so draw the form
{
  DrawForm();
}

function DrawForm()
{
include'testdiagnosis.php';
} 
?>

Link to comment
https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239092
Share on other sites

this code here

if (is_numeric($_POST['temp']))
{
   echo "Temperature should be numeric";
   $ready = false;
  }

 

if $_POST['temp'] is a number it will echo  out 'Temperature should be numeric'

 

change it to

 

if (!is_numeric($_POST['temp']))
{
   echo "Temperature should be numeric";
   $ready = false;
  }

Link to comment
https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239095
Share on other sites

oo i know i miss the

 

if (!is_numeric($_POST['temp']))
{
   echo "Temperature should be numeric";
   $ready = false;
  }

 

 

but the problem is now it doesnt run this statement

 

 

if ($ready)
{
   if ($_POST['temp']>37.5 && isset($_POST['running_nose'])) echo "You probably have cold.";
  
}

 

must i declare $ready ??

 

 

Link to comment
https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239556
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.