-3

Have this code i want to check if record exist in $pas before processing result then try to verify $pas by form input I have tried this:

$pas = "1234";
$text = "12345678910111213141516";
if(empty($pas)) {
    echo $text;
}
else
{
    if (isset($_POST["subscribe"]))
    {
        $phone = $_POST["phone"];
        if ($phone == $pas)
        {
            echo $text;
        }
        else
        {
            if ($phone != "$pass")
            {
                echo erro;
            }
        }
    } 
}
if(!isset($_POST["phone"]) || $_POST["phone"] != $pas)
{
    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>';
}

But I get result even when 'pas' is not there what am I doing Wrong?

  • 1
    where you want to check?? – K.B Nov 21 '17 at 12:54
  • is this related to a mysql database? – Funk Forty Niner Nov 21 '17 at 12:55
  • 1
    What’s the difference between this, and your previous question, https://stackoverflow.com/questions/47377332/how-do-i-verify-form-input-before-displaying-record ? – CBroe Nov 21 '17 at 12:57
  • 1
    @CBroe Yeah, that's what I was asking myself also. – Funk Forty Niner Nov 21 '17 at 12:58
  • `"$pass"` please dont do stuff like that. Use `$pass` as is, since using quotes around it doesnt do anything here except using more memory. That is because strings in double quotes get interpreted (dont know if interpreted is the right term here). – Manuel Mannhardt Nov 21 '17 at 12:58
  • 1
    what do you mean by this? *"How i do check if record exist in querry"* - db query? Your question's unclear. – Funk Forty Niner Nov 21 '17 at 12:59
  • Note: I did an edit of your question, proper indentation is critical. Look the answer from pr1nc3, he modified a } closure. Without indentation, it is hard to read your code. – Nic3500 Nov 21 '17 at 13:00
  • [This is a comment](https://meta.stackoverflow.com/questions/358600/lets-send-new-users-off-to-see-the-wizard#comment526922_358600) in a [meta post](https://meta.stackoverflow.com/q/358600/1415724) that was created for posts just like this. – Funk Forty Niner Nov 21 '17 at 13:03
  • Thank you for your ever so lovely cooperation. – Funk Forty Niner Nov 21 '17 at 13:11

1 Answers1

0
<?php
$pas = "1234";
$text = "12345678910111213141516";
if(empty($pas)) {
    echo $text;
}
else
{
    if (isset($_POST["subscribe"]))
    {
        $phone = $_POST["phone"];
        if ($phone == $pas)
        {
            echo $text;
        }
        else
        {
            if ($phone != "$pass")
            {
                echo erro;
            }
        }
    }

if(!isset($_POST["phone"]) || $_POST["phone"] != $pas)
{
    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>';
}
}

Your else bracket was closing sooner than you wanted so your echo would be executed anyway as it was outside of your if/else

pr1nc3
  • 8,108
  • 3
  • 23
  • 36