0

The problem is with this line:

if $var LIKE '1800%';

and I'm not sure how to fix it. Thanks.

<?php 
//check to see if account number is like 1800*
if (isset($_POST['acct_number'])) {
$var = $_POST['acct_number'];
    if $var LIKE '1800%'; {
        //stop the code
        exit;
    } else {
        echo 'normal account number';
    }
}
?>
Dark Knight
  • 6,116
  • 1
  • 15
  • 37
Blondie
  • 59
  • 5
  • It looks like you are trying to mix MySQL and PHP. – GrumpyCrouton Sep 17 '20 at 19:29
  • Does this answer your question? [How to check if a string starts with a specified string?](https://stackoverflow.com/questions/2790899/how-to-check-if-a-string-starts-with-a-specified-string) – KHansen Sep 18 '20 at 05:23
  • Does this answer your question? [startsWith() and endsWith() functions in PHP](https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php) – Wibble Sep 18 '20 at 09:58

4 Answers4

2

Another way could be to use strpos()

if (strpos($var, '1800') === 0) {
   // var starts with '1800'
}
Ambrish Pathak
  • 3,813
  • 2
  • 15
  • 30
1

Use substr function to get first 4 characters and compare it with 1800.

if(substr($var, 0, 4) == '1800')
{
 // your code goes here.
}
``
Dark Knight
  • 6,116
  • 1
  • 15
  • 37
1

You need PHP not MySQL. For 1800% just check that it is found at position 0:

if(strpos($var, '1800') === 0) {
    //stop the code
    exit;
} else {
    echo 'normal account number';
}

If it can occur anywhere like %1800% then:

if(strpos($var, '1800') !== false) {
    //stop the code
    exit;
} else {
    echo 'normal account number';
}
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
1

I would use a regular expression for this preg_match('/^1800.+/', $search, $matches);

Ismael Moral
  • 722
  • 1
  • 9
  • 35