User
Pass
2FA
 
 

Problema PHP

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database
Author Message701
x3MeNToX
[Banned user]


Banned


Status: Offline
(since 21-01-2015 20:55)
Joined: 02 Feb 2014
Posts: 201, Topics: 54
Location: Pe la balta...

Reputation: 143
Votes: 5

        x3MeNToX 
Post Posted: 29-10-2014, 22:04:32 | Translate post to: ... (Click for more languages)

Salut! Am si eu o problema cu urmatorul cod:

Code:
<?php

 $a = rand(0, 21);
 $b = rand(2, 6);
if($_POST['submit']) {
   if($_POST['rez'] != $a+$b) {
         $eroare[] = "Rezultat incorect!";
      }
      if(empty($eroare) === true) {
         echo "Ai intrat!";
      }
}         
?>
<html>
<form action="" method="post">
<?php echo $a, "+", $b; ?>
<input type="text" name="rez">
<input type="submit" value="Go" name="submit">
<?php
if(empty($eroare) === false) {
   echo implode("<pre> </pre>", $eroare);
}
?>
</form>


Care e problema cu el? Chiar daca scriu rezultatul corect, tot zice ca e incorect.
Sa fie oare din cauza lui a sau b?

Nu vad care sa fie problema. Am incercat multe variante. Niciuna nu a mers


Eating dust it'll just make me angrier! Wait, let me remind you of what got me this far:
``Don't Be a Retard! Be a King? Think Not? Why Be a King When You Can Be a GOD?,, - Eminem 2013
Cause it feels so empty Without Me
Calafat.Freakz.Ro - Server Clasic
0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
Raster

[ACNA]



Status: Offline
(since 02-09-2016 09:51)
Joined: 24 Feb 2011
Posts: 5377, Topics: 210
Location: In my mind palace

Reputation: 765.4
Votes: 81

     
Post Posted: 30-10-2014, 00:15:32 | Translate post to: ... (Click for more languages)

Paaaaai, $a+$b din script in momentul in care tu dai submit e diferit fata de ala pe care-l verifica scriptul.

Nu stiu daca intelegi ce vreau sa spun, anyway, citeste codul:
->generezi a,b
->le afisezi in html
->userul le vede, introduce rezultatul si da submit, moment in care scriptul e apelat din nou
-> se genereaza iarasi a,b (DIFERITE FATA DE PRIMELE 2, bine, ai o sansa sa fie aceleasi, dar tu nu te bazezi pe aia)
->intra si if-ul ala la socoteala si calculeaza a+b, doar ca astea sunt diferite fata de primele

Bla bla, te-ai prins tu.


LE:
Code:
if(empty($eroare) === false) {
   echo implode("<pre> </pre>", $eroare);
}


Poti folosi if(!empty($eroare) {}, citesti 'if not empty', adica daca empty e fals bla bla. Also, nu ai neaparata nevoie de 3x=, compari cu un bool si e clar ce primesti din functia aia.



воронья
0 0
  
Back to top
View user's profile Send private message
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database  


The time now is 02-05-2024, 07:44:22
Copyright info

Based on phpBB ro/com
B

 
 
 







I forgot my password


This message appears only once, so
like us now until it's too late ! :D
x