-1

I have this code below in achievement i want to verify if 1234 is inserted in form before output the record in $text i have tried:

 $text = "12345678910111213141516171819202121";

 $pas = "1234";

 if(isset($_POST["subscribe"]))

 {

 $phone = $_POST["phone"];

 if($phone = "$pas")
 {

 echo $text;

 }
if($phone != "$pass")
 {

 echo erro;

 }

 }

     echo '<form action="#" method="POST">
Your Phone Number <br> <input type="text" name="phone" value="080"/><input type="submit" name="subscribe" value="SEND PAYMENT"/></form></div>';

but i get record in $text when empty or wrong $pas is submited in the form. Great thanks in advance

mega6382
  • 9,211
  • 17
  • 48
  • 69
  • You'll have to use double equal in order to check if those two variables are "equal". if($phone == $pas) { echo $text; } else { echo "error"; } – Ofir Baruch Nov 19 '17 at 13:23

1 Answers1

1

This is because = is assignment operator and == is equality comparison operator. So try the following instead:

 if($phone == $pas)
 {

    echo $text;

 }

Edit: Answer to the question in the comment. You should avoid echo when outputing html, So try the following code to hide the submit button when $phone matches. Like:

<?php 
$text = "12345678910111213141516171819202121";
$pas = "1234";

if (isset($_POST["subscribe"]))
{
    $phone = $_POST["phone"];
    if ($phone == $pas)
    {
        echo $text;
    }

    if ($phone != "$pass")
    {
        echo erro;
    }
}

?>
<form action="#" method="POST">
    Your Phone Number <br /> 
    <input type="text" name="phone" value="080"/>
    <?php if(isset($_POST["phone"]) || $_POST["phone"] != $pas): ?>
        <input type="submit" name="subscribe" value="SEND PAYMENT"/>
    <?php endif; ?>
</form>
mega6382
  • 9,211
  • 17
  • 48
  • 69
  • Woww great knowledge @mega3682 but how do i remove form submiter if result is true example am expected to have just record in $text only at page example 12345678910111213141516171819202121 only form input not include can i really achieve that? – Et'z Godknows Peters Nov 19 '17 at 13:37
  • Yes, try my updated answer. – mega6382 Nov 19 '17 at 13:46
  • Thanks for the knowlege please check your answers if it really in other for further readers currently your answers put no different as return in my server i have risk out if(!isset($_POST["subscribe"]) || $_POST["phone"] != $pas) { in soluction thanks allot – Et'z Godknows Peters Nov 19 '17 at 14:23