How can I use an if-condition for storing data into the database?
<p>I have a very strange problem. This is my update.php, which is storing the <strong>user</strong> and <strong>date</strong> in the database by clicking the submit button:</p>

<pre><code>   &lt;?php
    session_start();

    require('database.php'); 
    require('header.php');

    if(!$user-&gt;is_logged_in()){ 
    header('Location: index.php'); 
    } 

    $id = 0;
    $user = $_SESSION['username'];

    if ( !empty($_GET['id'])) {
    $id = $_REQUEST['id'];
    $animal = $_REQUEST['animal'];
    }

    if ( !empty($_POST)) {
    $id = $_POST['id'];

    $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql1 = "UPDATE animals set user1 = ?, date1 = NOW() WHERE id = '$id'";
    $q = $pdo-&gt;prepare($sql1);
    $q-&gt;execute(array($user));
    Database::disconnect();
    header("Location: index.php");                      
    } 
    ?&gt;

    &lt;form action="update.php" method="post"&gt;
    &lt;input type="hidden" name="id" value="&lt;?php echo $id;?&gt;"/&gt;
    &lt;button type="submit"&gt; Submit&lt;/button&gt;
    &lt;/form&gt;
</code></pre>

<p>It is working very well so far. But I need to make a condition, that means, only do the stuff if <code>$animal == 1</code>.</p>

<p>Now there comes my problem.</p>

<p>I simply put my if condition around my sql request:</p>

<pre><code>if ($animal == 1){
    $sql1 = "UPDATE animals set user1 = ?, date1 = NOW() WHERE id = '$id'";
            $q = $pdo-&gt;prepare($sql1);
}
</code></pre>

<p>I need this because later I also want to write:</p>

<pre><code>   if ($animal == 2){
        $sql2 = "UPDATE animals set user2 = ?, date2 = NOW() WHERE id = '$id'";
                $q = $pdo-&gt;prepare($sql2);
    }
</code></pre>

<p>But it is simply not working. If I use the <code>if-condition</code>, then my code is just not working anymore, means nothing is stored in the database and also the redirect to index.php is not working. Can anybody help me?</p>