I’m trying to make a vote script in PHP but I have some syntax error. I’m a real rocky when it comes to PHP so please be kind…
My “doft” value is NaN if not set?
if ( ! isset(int) $_POST["doft"] ){
$new_value_doft = $prev_value_doft + $doft;
$new_num_votes_doft = $prev_num_votes_doft + 1;
}
else{
$new_value_doft = $prev_value_doft + $doft;
$new_num_votes_doft = $prev_num_votes_doft;
}
The isset method checks if a variable or index is actually set. You want to use it like this
or, to check if it is not set
At the same time, you can make sure/check wether the posted value is an integer like using the is_int method:
Or simply use the is_numeric method
Your given script should probably look like this:
Use is_numeric() function provided by PHP
Just checking isset does not tell you if it is a valid number or not.
Your
if
statement isn’t working.It should look something like this.
if (!isset($_POST['doft']))
What you have now isn’t valid, thus the syntax error.