Jump to content

form validiation


desithugg

Recommended Posts

Use is numeric:
[code]<?php

if(isset($_POST['submit']))
{
    if(is_numeric($_POST['numb']))
    {
        echo "Is numeric!";
    }
    else
    {
        echo "Is not numeric!";
    }
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <input type="text" name="numb" value="<?php echo @$_POST['numb']; ?>" /><br />
  <input type="submit" name="submit" value="Check number" />
</form>[/code]
Or you can use ereg
Link to comment
https://forums.phpfreaks.com/topic/15607-form-validiation/#findComment-63494
Share on other sites

umm would this work i think it shoudl
[code]<?
$price = $_POST['price'];
if ($price == "")
{
echo"Sorry you didn't fill in the price field.";
exit();
}
if(is_numeric($price]))
{
$query = "INSERT INTO sold (price) VALUES ('$price')"; 
$result = mysql_query($query);
}
  else
    {
        echo "Sorry you may only enter Numbers in the price field.Please go back and fix you're mistakes.";
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/15607-form-validiation/#findComment-63500
Share on other sites

Rather than do this:
[code]<?
$price = $_POST['price'];
if ($price == "")
{
echo"Sorry you didn't fill in the price field.";
exit();
}
if(is_numeric($price]))
{
$query = "INSERT INTO sold (price) VALUES ('$price')"; 
$result = mysql_query($query);
}
  else
    {
        echo "Sorry you may only enter Numbers in the price field.Please go back and fix you're mistakes.";
}
?>[/code]
I'd do this:
[code]<?php

if(isset($_POST['price']) && !empty($_POST['price']) && is_numeric($_POST['price']))
{
    $price = addslashes($_POST['price']);

    $query = "INSERT INTO sold (price) VALUES ('$price')";
    $result = mysql_query($query);
}
else
{
        echo "PLease verify you have filled in the price field correctly";
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/15607-form-validiation/#findComment-63502
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.