In the form the user needs to enter two values. These values should only float numbers. I have searched how to validate to input float values
, and the way I did it, it accepts integers. I used the filter_var()
function with the FILTER_VALIDATE_FLOAT
. It accepts successfully the float scores, but it also accepts the integers which I don't want it.
savelibscores.php
<?php
define('DB_NAME','');
define('DB_USER','');
define('DB_PASSWORD','');
define('DB_HOST','localhost');
$connect = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if(!$connect){
die('Could not connect:'.mysql_error());
}
$db_selected=mysql_select_db(DB_NAME,$connect);
if(!$db_selected){
die('Can\'t use'.DB_NAME.':'.mysql_error());
}
if(isset($_POST['submit'])){
$value1=$_POST['s3'];
$value2=$_POST['s4'];
$value3=$_POST['year'];
if(filter_var($value1,FILTER_VALIDATE_FLOAT) && filter_var($value2,FILTER_VALIDATE_FLOAT)) {
echo 'TRUE.';
} else {
echo 'FALSE.';
}
if(!empty($value1) && !empty($value2) && !empty($value3)){
$sql=mysql_query("INSERT INTO `library`(s3,s4,year) VALUES ('".$value1."','".$value2."','".$value3."')")or die(mysql_error());
}
else{
echo "Please fill all the fields. Please be sure to use float values also.";
}
}
?>