Hi,

I'm having trouble parsing $_POST for use in my PHP form processor.

Sometimes a number will come out as a integer ($x = 1), sometimes it
comes out as a text string ($x = "1").

Could someone please explain (or point me to an explanation of) how
information is stored in $_POST by a form?

Sidenote:

The origin form is generated by PHP from MySQL 2 database tables which
are formatted:

ID#     TITLE     URL     VOTES

In the original version my form sent the selected TITLEs, but I
changed it to send the ID# to help prevent injection and surrounded my
processing code with a simple if/else statement:

     if (is_int(ID#1) && is_int(ID#2)){
          // form processing code
     } else {
          echo "There was an error in form submission..."
     }

And it worked perfectly at first.  Then later (after adding more code
to my processor) it stopped working and debugging revealed that the
variables were being sent as text strings instead of numbers.

Possibility:

I altered the code of the form page slightly to clean it up.  I was
saying things like:

echo "<td>".$moviename[$x]."</td><td>".$votes[$x]."</td><td><input
name=\"mname\" value=\"".$id[$x]."\" type=\"radio\"></td>";

Then I clinked to the fact that if you put a variable inside the
double quotes of an echo statement it will echo the _value_ of the
variable instead of the text...  So the above would change to:

echo "<td>$moviename[$x]</td><td>$votes[$x]</td><td><input
name=\"mname\" value=\"$id[$x]\" type=\"radio\"></td>";

Could the change in the echo statements have caused my integers to be
expressed as text strings in $_POST?

Reply via email to