PHP "Enter code to win" Solution reading a simple .txt file
<p>I want to create a competition. I'm not good with php but can see this could be the only way to do it. I would like to create a script using a simple one field form where the customer enters a code and when they click submit it will look at a text file and any matching results will be returned with a congratulations page and any not matching will return a sorry you haven't won this time page. Would this be fairly simple to do?</p>

<p>I could expand on this and have the whole list of 13,000 codes in a sql database and once a code is entered it exhausts that code so if entered again it will return a sorry, this code has already been entered/used?</p>

<p>Would there be a simple way of emailing an address saying something has been submitted?</p>

<p>Edit:</p>

<p>Using an answer below I have got this far:</p>

<pre><code>    &lt;?php
$hostname = "localhost";
$username = "*****";
$password = "*****";
$code = $_POST[ 'code' ];

  if ( $client_code ) {

    $db = new PDO( 'mysql:host=$hostname;dbname=*****", $username, $password);

    $statement = $db -&gt; prepare( 'SELECT 1 FROM codes WHERE code = ?' );
    $statement -&gt; bindParam( 1, $code );
    $statement -&gt; execute();

    $result = $statement -&gt; fetchAll();

    if ( $result ) {
      header( 'Location: success.php' ); // Redirects to success page
      die();
    }
      header( 'Location: fail.php' ); // Redirects to fail page
      die();
    }

   else {
    header( 'Location: no_code.php' ); // Redirects to no code entered page
    die();
  }

?&gt;
</code></pre>

<p>But it keeps flagging up with this error</p>

<p>Parse error: syntax error, unexpected T_STRING in mysite/mypahe.php on line 11</p>

<p>Can anyone help?</p>
