Reputation: 5533
I have a remote php program that generates 2 random numbers, I call to it on my form page to populate a text box used in validation. I can't get it to return the numbers.
<?php
$randomNum = rand(0,9);
$randomNum2 = rand(0,9);
echo ($randomNum + $randomNum2);
$randomNumTotal = $randomNum + $randomNum2;
?>
It is returning the total, not # + # Please help!
OK, thanks to the help below I got the output to be correct on the page. What I'm doing is the parent page brings in forms via AJAX. The forms are validated by a remote PHP script "random.php" in the forms there is a math problem for a somewhat human verification, the math problem is populated by the "random.php" file via .get command. Got that working. The issue now is that I can't solve the problem correctly... the answer input has this validation:
SomeName: {
equal: "<? php echo $randomNumTotal ?>
}
but it's not working...any ideas?
Upvotes: 2
Views: 338
Reputation: 2203
This might help: echo "$randomNum + $randomNum2 = " . $randomNum + $randomNum2;
Upvotes: 0
Reputation: 9174
You use the .
in php for String concatenation
Try $randomNumTotal = $randomNum ."+". $randomNum2;
Upvotes: 4
Reputation: 77044
+
is an addition, while .
is a string concatenation:
echo $randomNum . '+' . $randomNum2;
Upvotes: 1
Reputation: 4896
It sounds like you want to concatenate the digits rather than add them, which is .
rather than +
:
echo $randomNum . $randomNum2;
Upvotes: 2