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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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