Jump to content

Archived

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

phplee

php arithmic trouble

Recommended Posts

<?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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

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.