-2

I have a product code verification script. How to make it so that after the lightning of a code, it can not be used a second time.

<?php 

require_once('captcha.php');

$error = $verified = false;

if($_POST){

  mysql_connect('localhost', 'root', 'root');
  mysql_select_db('code');

  if(!PhpCaptcha::Validate($_POST['captcha'])){

    $error = 'Anti-bot code is not valid!';

  }else{

    $query = "SELECT product_title FROM code1 WHERE code_plain='".mysql_real_escape_string($_POST['code'])."'";



    $result = mysql_query($query) or die(mysql_error());
    $res = mysql_fetch_assoc($result);
    if(mysql_num_rows($result)>0) $verified = $res['product_title'];


      else $error = '<b>This poruduct code is not valid or doesn\'t exist!</b>';

  } 

}

?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

0
if(mysql_num_rows($result)>0) {
   $verified = $res['product_title'];
   mysql_query('DELETE FROM code1 WHERE 
   code_plain='".mysql_real_escape_string($_POST['code'])."'";
 }

But you shouldn't be using mysql_ -functions as they are obsolete! Take a look to PDO (http://php.net/pdo) for example.

Athene noctua
  • 82
  • 1
  • 7