0

Hi all kinda new with php and forms so wondering if someone could help me out. I have a form with 4 text fields which are used to add the fields with the result in the 4th field. When i submit the field result the 4th field then displays the result but does not show the result in the $_Post array. How do i get the result to show in the array?
Here is my code. Thanks for the help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<?php
$a = $_POST[1];
$b = $_POST[2];
$c = $_POST[3];
$d = $a + $b + $c;
print_r ($_POST);
?>

</head>

<body>
 <form action="" method="post">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><input name="1" type="text" value="<?= $a ?>" /></td>
    <td><input name="2" type="text"  value="<?= $b ?>"/></td>
    <td><input name="3" type="text" value="<?= $c ?>"/></td>
    <td><input name="4" type="text" value="<?= $d ?>" /></td>
    <td><input name="submit" type="submit" value="submit" /></td>
  </tr>
</table>
</form>
</body>
</html>
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by phpbeginners
0

Try this..you need some quotes (You also need a form action..which can be easily fixed by PHP_SELF which will insert the name of the current PHP page):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<?php
  $a = $_POST['1'];
  $b = $_POST['2'];
  $c = $_POST['3'];
  $d = $a + $b + $c;
?>

</head>

<body>
  <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
  <table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><input name="1" type="text" value="<?= $a ?>" /></td>
      <td><input name="2" type="text"  value="<?= $b ?>"/></td>
      <td><input name="3" type="text" value="<?= $c ?>"/></td>
      <td><input name="4" type="text" value="<?= $d ?>" /></td>
      <td><input name="submit" type="submit" value="submit" /></td>
    </tr>
  </table>
</form>
</body>
</html>

Edited by FlashCreations: n/a

0
in you code $d is not part of POST.

$a = $_POST[1];
$b = $_POST[2];
$c = $_POST[3];
$d = $a + $b + $c;
print_r ($_POST);

try this and you will see the value.
$a = $_POST[1];
$b = $_POST[2];
$c = $_POST[3];
$d = $_POST[4];
print_r ($_POST);

see my next post

Edited by phpbeginners: n/a

0

Try to Change your code to this.

if(isset($_POST['submit'])) {
$a = $_POST[1];
$b = $_POST[2];
$c = $_POST[3];
$d = $a + $b + $c;
$_POST[4]=$d;
}

Edited by phpbeginners: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.