I’m building a web form in php, and while at testing the code, it is not showing the correct way, that I wanna.
I mean to say
It is showing integer value as false, as an example
$int = 011;
$int2 = !is_int($int);
echo $int2;
it is showing this result as 1, but only when I enter the value through form with post method.
While if I test the same in another script without post and form processing then it is working fine.
So, I wanna know why it is showing such weired behavior ?
Here is the full code of my form:
<?php
require_once "includes/functions.php";
require_once "database.php";
if(!loggedin())
{
header("Location: login.php");
}
if($_GET == false)
{
$user = $_SESSION['NORMAL_USER'];
$uid = $_SESSION['USER_ID'];
echo $uid;
echo "<br />";
}
if($_POST)
{
if(htmlCheck($_POST))
{
echo "<meta http-equiv=refresh content=4>";
$message = htmlCheck($_POST);
}
else
{
$expected = array('PAN', 'mobile', 'std', 'fone', 'father', 'day', 'month', 'year', 'flat', 'area', 'town', 'state', 'PIN');
$required = array('PAN', 'mobile', 'std', 'fone', 'father', 'day', 'month', 'year', 'flat', 'area', 'town', 'state', 'PIN');
$missing = array();
$error = array();
foreach($_POST as $key => $value)
{
$temp = is_array($value) ? $value : trim($value);
//if empty and required, add to $missing array
if(empty($temp) && in_array($key, $required))
{
array_push($missing, $key);
} // otherwise, assign to a variable of the same name as $key
elseif(in_array($key, $expected))
{
$temp = mysql_real_escape_string(htmlentities(strip_tags($temp)));
${$key} = $temp;
}
}
echo "<pre>";
print_r($_POST);
print_r($missing);
echo "</pre>";
echo "<hr />";
echo "$std";
echo "<br />$fone<br />";
$int = !is_int($std);
echo $int."<br />";
$int1 = !is_int($fone);
echo $int1."<br />";
$int3 = !is_int($std) || !is_int($fone);
echo $int3."<br />";
if(empty($missing))
{
if(strlen($PAN) != 10)
{
$message = "You have not entered the correct value for PAN Number. Please rectify it.";
//array_push($error, $message);
}
elseif(!is_numeric($mobile) || strlen($mobile) != 10)
{
$message = "You have not entered the correct Mobile No.";
}
elseif(!is_int($std) || !is_int($fone))
{
$message = "You have not entered the correct STD or Phone No.";
}
elseif(!filter_var($father, FILTER_SANITIZE_STRING))
{
$message = "You have not entered the ";
}
elseif(!is_int($day) || !is_int($month) || !is_int($year))
{
$message = "You have not entered the correct value for your Date of Birth";
}
elseif(!filter_var($flat, FILTER_SANITIZE_STRING))
{
$message = "You have not entered the correct value for the flat";
}
elseif(!filter_var($area, FILTER_SANITIZE_STRING))
{
$message = "You have not entered the correct value for the area";
}
elseif(!filter_var($town, FILTER_SANITIZE_STRING))
{
$message = "You have not entered the correct value for the town";
}
elseif(!filter_var($state, FILTER_SANITIZE_STRING))
{
$message = "You have not entered the correct value for the state";
}
elseif(!is_int($PIN) && strlen($PIN) != 6)
{
$message = "Please provide the correct PIN CODE of your area which should be of 6 digit only.";
}
else
{
$date = "$year-$month-$day";
$phone = "$std-$fone";
$sql = "insert into userinfo(uid, PAN, DOB, mobile, phone, father, flat, area, town, state, pin) ";
$sql .= "values('$uid', '$PAN', '$date', '$mobile', '$phone', '$father', '$flat', '$area', '$town', '$state', '$PIN')";
$res = query($sql);
if($res)
{
$message = "You have successfully entered the values. Now we will contact you soon if further information would be needed.";
$tableid = mysql_insert_id();
echo $tableid;
}
}
}
else
{
$message = "Please fill all the fields.";
}
}
}
include_once "layout/header.php";
if($user) echo "Welcome ". ucfirst($user).", this is your first time here on this website, so please have a look below form and fill it so that it will be helpful for us to file your return.";
?>
<?php if(isset($message)) echo "<p>".$message."</p><br />"; ?>
<form action="" method="post" class="update">
<fieldset class="update">
<legend class="update">General Information</legend>
<table class="update">
<tr>
<td><label class="update" for="PAN">PAN Card Number: </label></td>
<td><input type="text" name="PAN" title="Provide Your PAN Number" size="15" maxlength="12" /></td>
</tr>
<tr>
<td><label class="update" for="mobile">Mobile Number: </label></td>
<td><input type="text" name="mobile" title="Provide Your Mobile Number" size="15" maxlength="10" /></td>
</tr>
<tr>
<td><label class="update" for="std">Phone Number </label></td>
<td><input type="text" name="std" title="STD code:" maxlength="5" size="5" />
<input type="text" name="fone" title="Phone number" size="10" maxlength="10" /></td>
</tr>
<tr>
<td><label class="update" for="father">Father's Name: </label></td>
<td><input type="text" name="father" title="Your Father's Name:" size="21" /></td>
</tr>
<tr>
<td><label class="update" for="DOB">Date of Birth: </label></td>
<td>
<select name="day">
<option>Day</option>
<?php
for($i = 1; $i<= 31; $i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
<select name="month">
<option>Month</option>
<?php
for($i= 1; $i <= 12; $i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
<select name="year">
<option>Year</option>
<?php
for($i = 1940; $i <= 2000; $i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
</td>
</tr>
</table>
</fieldset>
<fieldset class="update">
<legend class="update">Address Information</legend>
<table class="update">
<tr>
<td><label class="update" for="flat">Flat/Door/Block No.: </label></td>
<td><input type="text" name="flat" title="Your Flat/Door No." /></td>
</tr>
<tr>
<td><label class="update" for="area">Area Locality: </label></td>
<td><input type="text" name="area" title="Your Area or Locality" /></td>
</tr>
<tr>
<td><label class="update" for="town">Town/City/District: </label></td>
<td><input type="text" name="town" title="Your Town or City or District" /></td>
</tr>
<tr>
<td><label class="update" for="state">Your State: </label></td>
<td><input type="text" name="state" title="Your State Name" /></td>
</tr>
<tr>
<td><label class="update" for="PIN">PIN CODE: </label></td>
<td><input type="text" name="PIN" title="PIN CODE of your area." size="10" maxlength="6" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" title="Please check before submitting" size="10" value="Submit" /></td>
</tr>
</table>
</fieldset>
</form>