Jump to content

[SOLVED] more then one submit butons


alin19

Recommended Posts

the code is not so important, i need more that one submit butons, for example i enter data into the first collumn, and press submit buton, just to calculate first collumn; the second the same, the third and the fourth the same

 

can that be done?

 

<?php

 

if($_SERVER['REQUEST_METHOD'] == 'POST')

 

{

$a1 = $_POST['aunu'];

$a2 = $_POST['adoi'];

$a3 = $_POST['atrei'];

$a4 = $_POST['apatru'];

 

$b1 = $_POST['bunu'];

$b2 = $_POST['bdoi'];

$b3 = $_POST['btrei'];

$b4 = $_POST['bpatru'];

 

$c1 = $_POST['cunu'];

$c2 = $_POST['cdoi'];

$c3 = $_POST['ctrei'];

$c4 = $_POST['cpatru'];

 

$d1 = $_POST['dunu'];

$d2 = $_POST['ddoi'];

$d3 = $_POST['dtrei'];

$d4 = $_POST['dpatru'];

 

$e1 = $_POST['eunu'];

$e2 = $_POST['edoi'];

$e3 = $_POST['etrei'];

$e4 = $_POST['epatru'];

 

 

$z1 = $_POST['zunu'];

$z2 = $_POST['zdoi'];

$z3 = $_POST['ztrei'];

$z4 = $_POST['zpatru'];

 

 

$x1= number_format($z1*($e1/100*($b1-($d1/100*$b1)-$a1-(($c1+0.08)/100*$a1))), 4, '.', '');

$p1= number_format($z1*($b1-(($d1/100*$b1)+$a1+(($c1+0.08)/100*$a1)+$x1/300)), 4, '.', '');

 

$x2= number_format($z2*($e2/100*($b2-($d2/100*$b2)-$a2-(($c2+0.08)/100*$a2))), 4, '.', '');

$p2= number_format($z2*($b2-($d2/100*$b2)-$a2-(($c2+0.08)/100*$a2))-$x2, 4, '.', '');

 

$x3= number_format($z3*($e3/100*($b3-($d3/100*$b3)-$a3-(($c3+0.08)/100*$a3))), 4, '.', '');

$p3= number_format($z3*($b3-($d3/100*$b3)-$a3-(($c3+0.08)/100*$a3))-$x3, 4, '.', '');

 

$x4= number_format($z4*($e4/100*($b4-($d4/100*$b4)-$a4-(($c4+0.08)/100*$a4))), 4, '.', '');

$p4= number_format($z4*($b4-($d4/100*$b4)-$a4-(($c4+0.08)/100*$a4))-$x4, 4, '.', '');

 

$x= number_format($x1+$x2+$x3+$x4, 4, '.', '');

$p= number_format($p1+$p2+$p3+$p4, 4, '.', '');

 

if ($x1<0)

$x1 = 0;

if ($x2<0)

$x2 = 0;

if ($x3<0)

$x3 = 0;

if ($x4<0)

$x4 = 0;

}

 

?>

 

<html>

<body BACKGROUND="mapa2.jpg">

<form name="check" method="post">

</br></br></br></br></br></br>

<table width="800" border="2" cellpadding="0" cellspacing="2"  align="left">

 

 

 

 

<tr>    <td></td>

<td><font color="red" size="5"> ACTIUNEA 1</font></td>

<td><font color="red" size="5"> ACTIUNEA 2</font></td>

<td><font color="red" size="5"> ACTIUNEA 3</font></td>

<td><font color="red" size="5"> ACTIUNEA 4</font></td>

</tr>

 

<tr>   

 

 

    <td ><font color="green" size="3">NUMAR ACTIUNI</font></td>

   

<td ><font color="green" size="3"> <input name="zunu" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="zdoi" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="ztrei" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="zpatru" type="text" id="unu" /></font></td>

 

</tr>

 

 

 

 

 

<tr>   

 

 

    <td ><font color="green" size="3">PRET CUMPARARE</font></td>

   

<td ><font color="green" size="3"> <input name="aunu" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="adoi" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="atrei" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="apatru" type="text" id="unu" /></font></td>

 

  </tr>

 

 

 

 

<tr>

 

    <td ><font color="green" size="3">PRET VANZARE</font></td>

   

<td ><font color="green" size="3"> <input name="bunu" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="bdoi" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="btrei" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="bpatru" type="text" id="unu" /></font></td

  </tr>

 

 

<tr> <td ><font color="green" size="3">COMISION CUMPARARE</font></td>

    <td ><font color="green" size="3"> <input name="cunu" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="cdoi" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="ctrei" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="cpatru" type="text" id="unu" /></font></td

  </tr>

 

 

 

<tr> <td ><font color="green" size="3">COMISION VANZARE</font></td>

    <td ><font color="green" size="3"> <input name="dunu" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="ddoi" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="dtrei" type="text" id="unu" /></font></td>

<td ><font color="green" size="3"> <input name="dpatru" type="text" id="unu" /></font></td>

  </tr>

 

 

 

<tr>

<td><font color="green" size="3">COMISIONUL STATULUI</font></td>

<td ><font color="green" size="3"> <input name="eunu" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="edoi" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="etrei" type="text" id="unu" /></font></td>

 

<td ><font color="green" size="3"> <input name="epatru" type="text" id="unu" /></font></td>

</tr>

 

 

 

<tr>

<td ><font color="green" size="3"></font></td>

 

<td  valign="" align="center"><input type="submit" name="CALCULEAZA" value="CALCULEAZA" /></td>

 

</br></font></td>

   

<td ><font color="green" size="3"></font></td>

 

<td ><font color="green" size="3"></font></td>

<td ><font color="green" size="3"></font></td

 

 

 

</tr>

 

 

 

<tr>

<td ><font color="green" size="3">IMPOZIT PE ACTIUNI</font></td>

 

<td ><font color="red" size="3">

<?php

if(isset($x1)) {

echo $x1;  }

?>

 

</br></font></td>

 

   

<td ><font color="red" size="3">

<?php

if(isset($x2)) {

echo $x2;  }

?>

 

</br></font></td>

 

 

<td ><font color="red" size="3">

<?php

if(isset($x3)) {

echo $x3;  }

?>

 

</br></font></td>

 

<td ><font color="red" size="3">

<?php

if(isset($x4)) {

echo $x4;  }

?>

 

</br></font></td>

 

 

 

</tr>

 

 

 

<tr>

<td ><font color="green" size="3">PROFIT NET PE ACTIUNI</font></td>

 

<td ><font color="red" size="3">

<?php

if(isset($p1)) {

echo $p1;  }

?>

 

</br></font></td>

 

   

<td ><font color="red" size="3">

<?php

if(isset($p2)) {

echo $p2;  }

?>

 

</br></font></td>

 

 

<td ><font color="red" size="3">

<?php

if(isset($p3)) {

echo $p3;  }

?>

 

</br></font></td>

 

<td ><font color="red" size="3">

<?php

if(isset($p4)) {

echo $p4;  }

?>

 

</br></font></td>

 

 

 

</tr>

 

 

 

 

</br></br>

 

 

<tr>

<td><font color="green" size="3">IMPOZIT TOTAL</font></td>

<td ><font color="red" size="3"><?php

if(isset($x)) {

echo $x;  }

?>

</font></td>

<td></td>

<td ><font color="green" size="3">PROFIT TOTAL</font></td>

<td ><font color="red" size="3"><?php

if(isset($p)) {

echo $p;  }

?>

</font></td>

 

</table>

</form>

</html>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/87037-solved-more-then-one-submit-butons/
Share on other sites

Are you wanting to click calculate and then reload the page with the answer or are you wanting it to display the answer immediately without reload? If the second option is what you want, you need javascript to go with this. If you are going strictly php with a reload on the page, why not just make 4 forms?

let's say that i have this; how can i asign $a1-$a4 that belongs to the first form?

 

 

 

  $a1 = $_POST['aunu'];

  $a2 = $_POST['adoi'];

  $a3 = $_POST['atrei'];

  $a4 = $_POST['apatru'];

 

  $b1 = $_POST['bunu'];

  $b2 = $_POST['bdoi'];

  $b3 = $_POST['btrei'];

  $b4 = $_POST['bpatru'];

 

  $c1 = $_POST['cunu'];

  $c2 = $_POST['cdoi'];

  $c3 = $_POST['ctrei'];

  $c4 = $_POST['cpatru'];

 

  $d1 = $_POST['dunu'];

  $d2 = $_POST['ddoi'];

  $d3 = $_POST['dtrei'];

  $d4 = $_POST['dpatru'];

 

  $e1 = $_POST['eunu'];

  $e2 = $_POST['edoi'];

  $e3 = $_POST['etrei'];

  $e4 = $_POST['epatru'];

 

 

  $z1 = $_POST['zunu'];

  $z2 = $_POST['zdoi'];

  $z3 = $_POST['ztrei'];

  $z4 = $_POST['zpatru'];

 

 

 

Why not do something like this

 

<?php
if($_POST['button'] == 'Submit Button1')
{
echo 'Button 1 was pressed';
}
elseif($_POST['button'] == 'Submit Button2')
{
echo 'Button 2 was pressed';
}
?>

<form action="<?=$_SERVER['PHP_SELF'] ?>" method="post">
<input name="button" type="submit" value="Submit Button1" />
<input name="button" type="submit" value="Submit Button2" /></form>

Just look for the value of each button, and then based upon the value do what you want with the data submitted... you could also name the buttons different and look for which one was set.

 

Thats my $ .02

 

Nate

Why not do something like this

 

<?php
if($_POST['button'] == 'Submit Button1')
{
echo 'Button 1 was pressed';
}
elseif($_POST['button'] == 'Submit Button2')
{
echo 'Button 2 was pressed';
}
?>

<form action="<?=$_SERVER['PHP_SELF'] ?>" method="post">
<input name="button" type="submit" value="Submit Button1" />
<input name="button" type="submit" value="Submit Button2" /></form>

Just look for the value of each button, and then based upon the value do what you want with the data submitted... you could also name the buttons different and look for which one was set.

 

Thats my $ .02

 

Nate

 

10x; this is what i need

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.