problem with POST
Posted: Tue Mar 11, 2008 3:16 am
Recently I start to read about php and started my little task to make a simple program in which I would generate
two integers (each of them is in range of 0 - 50) and ask user to enter sum of these two numbers.
Program should check entered value, compare with correct value and print a message, but in may case it always print not set.
My problem is that no matter what I enter for sum my program get nothing as input.
Can someone tell me what I am doing wrong?
(I know that my english is bad but please have understanding.)
Here is my code:
<HTML><HEAD></HEAD>
<BODY>
<?php
// generating integers
for ($i=0;$i<=9;$i++){
$p[$i]=rand(0,50);
}
//print html tag <table>
echo "<table>";
for ($i=1;$i<=5;$i++){
echo "<tr><td><b>Zadatak $i.</b> Zbroj brojeva </td><td>".$p[$i-1]." i ".$p[$i+4]."</td> <td>iznosi : </td><td> ";
echo "<input type=\"text\" name=\"zad.$i\" value = \"\" size = \"20\"></td>";
echo "</tr>";
}
echo "</table>";
//buttons for submit i reset
echo "<br><input type = \"submit\" name =\"submit\" value = \"Predaj na ocjenjivanje\"/>";
echo " ";
echo "<input type = \"reset\" name = \"erase\" value = \"Brisanje svih unosa\"/>";
echo "</form>";
?>
<?php
}else{
//check if something is entered for first answer
if (isset($_POST['zad1'])){
$value = htmlspecialchars($_POST['zad1']);
echo "Entered value is ".$value;
}else{
echo "not set";
}
}
?>
</BODY>
</HTML>
two integers (each of them is in range of 0 - 50) and ask user to enter sum of these two numbers.
Program should check entered value, compare with correct value and print a message, but in may case it always print not set.
My problem is that no matter what I enter for sum my program get nothing as input.
Can someone tell me what I am doing wrong?
(I know that my english is bad but please have understanding.)
Here is my code:
<HTML><HEAD></HEAD>
<BODY>
<?php
// generating integers
for ($i=0;$i<=9;$i++){
$p[$i]=rand(0,50);
}
//print html tag <table>
echo "<table>";
for ($i=1;$i<=5;$i++){
echo "<tr><td><b>Zadatak $i.</b> Zbroj brojeva </td><td>".$p[$i-1]." i ".$p[$i+4]."</td> <td>iznosi : </td><td> ";
echo "<input type=\"text\" name=\"zad.$i\" value = \"\" size = \"20\"></td>";
echo "</tr>";
}
echo "</table>";
//buttons for submit i reset
echo "<br><input type = \"submit\" name =\"submit\" value = \"Predaj na ocjenjivanje\"/>";
echo " ";
echo "<input type = \"reset\" name = \"erase\" value = \"Brisanje svih unosa\"/>";
echo "</form>";
?>
<?php
}else{
//check if something is entered for first answer
if (isset($_POST['zad1'])){
$value = htmlspecialchars($_POST['zad1']);
echo "Entered value is ".$value;
}else{
echo "not set";
}
}
?>
</BODY>
</HTML>