0

I'm trying to create a search on a website I'm making for homework with a database called animal that is saved on an easy php server. However, when I run the search, the php code shows up as text. Can someone please help me with this?

    <?php
    $criteria = $_GET["criteria"];
    $Field = $_GET["animal"];
    $link = mysql_connect('127.0.0.1', 'criteria', 'animal');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    $result = array(connection -> query("SELECT * FROM animal WHERE $Field Like %criteria%"));
    mysql_close($link);
    echo $result;
?>
  • 1
    Your query is missing `FROM`. – Gordon Linoff May 23 '17 at 17:37
  • You are also setting the $result = the query then echo $result right after. If you are planning on executing that query you need to call a method to do so first. – Jacob H May 23 '17 at 17:39
  • 3
    Possible duplicate of [PHP code is not being executed, instead code shows on the page](https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) – Tom Udding May 23 '17 at 17:42
  • You also have a space in your opening php tag ` php` should just be ` – Jonathan Kuhn May 23 '17 at 17:46

2 Answers2

2

I see that you have a space between the <? and php in the opening php tag.

Remove the space to use php tags. It should be <?php.

Jonathan Kuhn
  • 15,279
  • 3
  • 32
  • 43
Erik
  • 295
  • 2
  • 10
1
    $result = array(connection -> query("SELECT * animal WHERE $Field Like %criteria%"));

should be

    $result = array(connection -> query("SELECT * FROM animal WHERE $Field Like %$criteria%"));
Omis Brown
  • 199
  • 2
  • 16