Welcome to WebmasterWorld Guest from 54.163.68.15

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem with PHP function

and Form action="<?php print $PHP_SELF ?>"

   
9:14 pm on Aug 17, 2001 (gmt 0)

10+ Year Member



OK, I've been trying for hours to make this work but it won't work. Anyway I'm trying to make it calculate a set of numbers the user gives it and then let it give the result of the calculations in it's own fields on the same page.

here is the url if you want to see it

Here's the code
[se.ydi.com...]

<?php
function cmdSOM() {
$FreqMHz = (is_numeric($txtfsll_Freq));
$DistMi = (is_numeric($txtfsll_Dist));

$txtFSL = round(20 * log10($FreqMHz) + 20 * log10($DistMi) + 36.6,1);

$TXpwr = (is_numeric($txtTXpwr));
$TXcabloss = (is_numeric($txtTXcabloss));
$TXantgain = (is_numeric($txtTXantgain));
$RXantgain = (is_numeric($txtRXantgain));
$RXcabloss = (is_numeric($txtRXcabloss));
$RXsens = (is_numeric($txtRXsens));
$FSL = (is_numeric($txtFSL));

$txtSOM = round(($TXpwr - $TXcabloss + $TXantgain - $FSL + $RXantgain - $RXcabloss - $RXsens),1) ;
$txtRXsig = round(($TXpwr - $TXcabloss + $TXantgain - $FSL + $RXantgain - $RXcabloss),1);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<?php
if (is_numeric($txtfsll_Freq)) {
print "<script language=JavaScript><!--window.alert(Frequency in miles must be an INTEGER or a DECIMAL); //--></script>";
}
if (is_numeric($txtfsll_Dist)) {
print "<script language=JavaScript><!--window.alert(Distance in miles must be an INTEGER or a DECIMAL); //--></script>";
}
if (is_numeric($TXpwr)) {
print "<script language=JavaScript><!--window.alert(Transmit power must be an INTEGER or a DECIMAL); //--></script>";
}
if (is_numeric($TXcabloss)) {
print "<script language=JavaScript><!--window.alert(Transmit cable loss must be an INTEGER or a DECIMAL); //--></script>";
}
if (is_numeric($TXantgain)) {
print "<script language=JavaScript><!--window.alert(Transmit antenna gain must be an INTEGER or a DECIMAL); //--></script>";
}
if (is_numeric($RXantgain)) {
print "<script language=JavaScript><!--window.alert(Receive antenna gain must be an INTEGER or a DECIMAL); //--></script>";
}
if (is_numeric($RXcabloss)) {
print "<script language=JavaScript><!--window.alert(Receive cable loss must be an INTEGER or a DECIMAL); //--></script>";
}
if (is_numeric($RXsens)) {
print "<script language=JavaScript><!--window.alert(Receive sensitivity must be an INTEGER or a DECIMAL); //--></script>";
}
?>

<title>Untitled</title>
</head>

<body>

<table cellpadding="3" cellspacing="2" border="0" width="600">

<form name="main" action="<?php print $PHP_SELF ?>" method="GET">

<tr>
<td align="left" valign="top" bgcolor="#003366" colspan="2"><p class="form">Operting Frequency</td>
<td align="left" valign="top" bgcolor="#003366" colspan="3"><p class="form">Distance between Antenna</td></tr>
<tr>
<td align="left" valign="top" colspan="2"><input type="text" name="txtfsll_Freq" value="2400" size="7" maxlength="7"> (MHz)<br><br></td>
<td align="left" valign="top" colspan="3"><input type="text" name="txtfsll_Dist" size="7" maxlength="7"> (Miles)<br><br></td></tr>
<tr>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Tx Power</td>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Tx Cable Loss</td>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Tx Antenna Gain</td>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Rx Antenna Gain</td>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Rx Cable Loss</td></tr>
<tr>
<td align="left" valign="top"><input type="text" name="txtTXpwr" size="5" maxlength="5"> (dBm)<br><br></td>
<td align="left" valign="top"><input type="text" name="txtTXcabloss" size="5" maxlength="5"> (dB)<br><br></td>
<td align="left" valign="top"><input type="text" name="txtTXantgain" size="5" maxlength="5"> (dBi)<br><br></td>
<td align="left" valign="top"><input type="text" name="txtRXantgain" size="5" maxlength="5"> (dBi)<br><br></td>
<td align="left" valign="top"><input type="text" name="txtRXcabloss" size="5" maxlength="5"> (dBi)<br><br></td></tr>
<tr>
<td align="left" valign="top" bgcolor="#003366" colspan="5"><p class="form">Calculate</td></tr>
<tr>
<td align="left" valign="top" colspan="5"><input type="Submit" name="cmdSOM" value="Calculate SOM" ><br></td></tr>
<tr>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Rx Sensitivity</td>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Free Space Loss</td>
<td align="left" valign="top" bgcolor="#003366"><p class="form">Rx Signal Level</td>
<td align="left" valign="top" bgcolor="#003366" colspan="2"><p class="form">Theoretical System Operating Margin</td></tr>
<tr>
<td align="left" valign="top"><input id="txtRXsens" type="text" name="txtRXsens" value="-85" size="5" maxlength="5"> (dBm)<br><br></td>
<td align="left" valign="top"><input type="text" name="txtFSL" size="6" maxlength="6" value="<?php print cmdSOM($txtFSL) ?>"> (dB)<br><br></td>
<td align="left" valign="top"><input type="text" name="txtRXsig" size="6" maxlength="6" value="<?php print cmdSOM($txtRXsig) ?>"> (dBm)<br><br></td>
<td align="left" valign="top" colspan="2"><input type="text" name="txtSOM" size="6" maxlength="6" value="<?php print cmdSOM($txtSOM) ?>"> (dB)<br><br></td></tr>
</form>
</table>

Air

12:33 am on Aug 18, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you print the vars from within the function:

<?php
function cmdSOM() {
.
.
.
.
print "$txtFSL<br>";
print "$txtRXsig<br>";
print "$txtSOM";

}
?>

Do you get the correct results?

3:29 am on Aug 18, 2001 (gmt 0)

10+ Year Member



Don't "print" your function in the form's value parameter, just call it:
<?php cmdSOM($txtFSL) ?>
3:12 pm on Aug 20, 2001 (gmt 0)

10+ Year Member



Hi all,
To answer your guestion Air, nope I don't get an answer at all.

I'll try it out toadhall.

Thanks

4:34 pm on Aug 20, 2001 (gmt 0)

10+ Year Member



You know, I enter the numbers and then hit the submit button and it does not give me the result. If you look to the top, on the URL the string has the variables, but they have no value.

test-php-calc.php?txtfsll_Freq=2400&txtfsll_Dist=2&txtTXpwr=2&txtTXcabloss=2&txtTXantgain=2&txtRXantgain=2&txtRXcabloss=2&cmdSOM=Calculate+SOM&txtRXsens=-85&txtFSL=&txtRXsig=&txtSOM=

What am I doing wrong :o

10:55 pm on Aug 20, 2001 (gmt 0)

10+ Year Member



Got it working.
Thanks you all