Archived Boards and Threads... > Parham's PHP Tutorials

php operational verification (for example 8+1, 10-1 etc...)

(1/1)

Sinan ANDIRMAN:
firstly sorry for my english ...

I have written a code but the javascript as operand warning How do I get my screen to come?

codes are the following:

sayisal.php

--- Code: ---<?php

$islemler = array('-','+'); 
$say1 = rand(10,20); 
$say2 = rand(1,9); 
$say3 = rand(0,1); 
echo $say1.$islemler[$say3].$say2.' <form action="onay.php" method="post"> <input type="text" name="cevap"><input type="hidden" name="islem" value="'.$islemler[$say3].'"><input type="hidden" name="say1" value="'.$say1.'"><input type="hidden" name="say2" value="'.$say2.'"> 

</form> ';

?>
--- End code ---

onay.php

--- Code: ---<?php
 

if($_POST['islem']=='-'){ 
$deger = $_POST['say1'] - $_POST['say2']; 
}else{ 
$deger = $_POST['say1'] + $_POST['say2']; 


if($deger == $_POST['cevap']){ 
echo 'islem dogru'; 
}else{ 
echo 'islem yanlis';  


?>
--- End code ---


Sinan ANDIRMAN:
does anybody answer me about this topic ?

:
I don't understand what you're actually trying to achieve.

It seems to be some kind of calculator but if the intent is to prove PHP is functioning there are far better, smaller and more efficient ways of doing it.

Sinan ANDIRMAN:
hello arantor,

i want to make javascript warning window if value is false. etc:


--- Code: ---if (document.forms.creator.cevap.value != document.forms.creator.deger.value)
{
alert("islem yanlis");
return false;
}
--- End code ---

can you help me ?

:
The thing is, PHP only outputs HTML. You can make it output Javascript too but the Javascript still has to run on the user's browser, meaning that it won't actually really be useful for what you're trying to do - since all you can do from PHP is populate the form values, then run that popup warning in Javascript by adding that exact code into the <script> tag the PHP outputs.

In any case, does that JS code work on browsers other than IE?

Navigation

[0] Message Index

Go to full version