Jump to content


Photo

php arithmic trouble


  • Please log in to reply
1 reply to this topic

#1 phplee

phplee
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 May 2004 - 02:26 PM

<?php
$ans = $_POST[first] $_POST[calc] $_POST[second];
$message = "";
if (!isset($_POST[first]) == here) {
$message = "Welcome to the math machine";
} elseif (($_POST[first]) == ($_POST[first])) {
$message = "$_POST[first] $_POST[calc] $_POST[second] = $ans";
}
?>
this a peice of code from a test page i am trying out. $_POST[first] $_POST[calc] $_POST[second]; these are user inputs, they would make, E.G. 4 + 4, i want this to complete so that when i put $ans in my code it will give me 8, not 4 + 4.

any help on this matter will help me very much, and is much apreciated.
thanks loads
lee

#2 Milshak

Milshak
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 May 2004 - 07:16 PM

I think what's happening is that $ans is an array and the user imputs are separate elements try to concatinate the user imput

try this

$ans = $_POST[first] .$_POST[calc] .$_POST[second];

note the periods




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users