PHP / MYSQL help (Register system)

Hi everyone looking for a little help im making a registry system however i need to check to see if there is a key already in the database so a user cant just insert a random key here is my codes if anyone can help me…

[php]<?php include "base.php"; ?>

<?php if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $password2 = md5(mysql_real_escape_string($_POST['password_conf'])); $email = mysql_real_escape_string($_POST['email']); $location = mysql_real_escape_string($_POST['location']); $vcode = mysql_real_escape_string($_POST['vcode']); $checkusername = mysql_query("SELECT * FROM MineCraft_Login WHERE username = '".$username."'"); $checkcode = mysql_query ("SELECT * FROM MineCraft_Login WHERE vouchercode = '".$vcode."'"); $checkkeys = mysql_query ("SELECT * FROM keys WHERE Key = '".$vcode."'"); $checkcode3 = mysql_query ("SELECT * FROM keys WHERE Used = 'Y'"); $print = mysql_query ("SELECT * FROM keys"); if(mysql_num_rows($checkusername) == 1 ) { echo "

Error

"; echo "

Sorry, that username is taken. Please go back and try again.

"; } elseif ($password != $password2){ echo "

Error

"; echo "

Your passwords need to be the same

"; } elseif (mysql_num_rows($checkcode) == 1 and mysql_num_rows($checkkeys) != 1){ echo "

Error

"; echo "

This voucher code is in use

"; } else { $registerquery = mysql_query("INSERT INTO MineCraft_Login (username, password, email, location , vouchercode) VALUES('".$username."', '".$password."', '".$email."' , '".$location."','".$vcode."')"); if($registerquery) { echo "

Success

"; echo "

Your account was successfully created. Please click here to login.

"; } else { echo "

Error

"; echo "

Sorry, your registration failed. Please go back and try again.

"; } } }[/php]
  1. You are using obsolete Mysql Code. Use PDO (or Mysqli)
  2. Stop using MD5. It is far from secure.
  3. You are using four more query’s than you need.
  4. Select specific columns by name that you actually need, not the entire row with *
  5. You closed php only to open it right back up again. (Lines 1 &2)
  6. Toss lines 1-48 in the trash.

There is a link in my signature to a PDO bumpstart database to get you going in the right direction.

Sponsor our Newsletter | Privacy Policy | Terms of Service