Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doubt with Code

Status
Not open for further replies.

Amenotep

Programmer
Aug 7, 2013
6
What is wrong with this code below ?
<html>
<head></head>
<body>
<p align="center">Balance Table</p>
<table align="center" width="75%" border="1" bordercolor="#0000FF">
<tr>
<td><form align="center"><input type="text" name="$value1" size="40"></form></td>
<td><form align="center"><input type="text" name="$value2" size="40"></form></td>
<td><p align="center"><?php $balance=$value1+$value2; ?><?php print $balance; ?></p></td>
</tr>
</table>
</body>
</html>
 
you have to echo variables if you want them to show.

also there is loads wrong with the html. run it through a validator to fix.

Code:
<html>
<head></head>
<body>
<p align="center">Balance Table</p>
<table align="center" width="75%" border="1" bordercolor="#0000FF">
<tr>
<?php $value1 = isset($value1) ? $value1: 0; $value2 = isset($value2)? $value2 : 0; ?
<td><form align="center"><input type="text" name="<?php echo $value1; ?>" size="40"></form></td>
<td><form align="center"><input type="text" name="<?php echo $value2 ?>" size="40"></form></td>
<td><p align="center"><?php echo $value1 + $value2; ?></p></td>
</tr>
</table>
</body>
</html>
 
The code does not calculate the balance.
 
I see

Code:
<html>
<head></head>
<body>
<p align="center">Balance Table</p>
<table align="center" width="75%" border="1" bordercolor="#0000FF">
<tr>
<?php 
$value1 = isset($_GET['value1') ? $_GET['value1'] : 0; 
$value2 = isset($_GET['value2'])? $_GET['value2'] : 0; 
$balance = $value1 + $value2'
?>
<form align="center" method="GET" action="./">
<td>
<input type="text" name="value1" size="40" value="<?php echo $value1; ?>" />
</td>
<td>
<input type="text" name="value2" size="40" value="<?php echo $value2; ?>"/>
</td>
</form>
<td>
 <p align="center"><?php echo $balance; ?><br/>
 <input type="submit" value="Calculate"/>
 </p>
 </td>
</tr>
</table>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top