Hey all,
I need some help with a SQL issue, A close friend got a pre-wriiten website which has a issue, he asked me to look and I think I have found a fault and its in the SQL code, had a closer look to see if it was a spelling mistake or something easy to spot but can't see anything and SQL was never my strong point, I don't think its checking correctly, or its checking creating a new username then chanking again and if its duplicate not doing a 3rd check just issuing the username,
The basic issue it when someone clicks a link on the webpage its supposed to generate a username for them, now the first part of the username is fixed to the site name (not with www. or .com etc) and give a random string of numbers between 0-9000 so it would look like "user-123456" or "user-321" and then check to see if that username has already been given, if so generate a new username and check again and keep doing that untill it gives a unique username.
The problem is its not doing that, its generating the username OK but its not checking for duplicates and some duplicate usernames have started to appear causing problems. Each username is a different password (thats randomly generated too) although no duplicate passwords have been generated.
Here is the code which is in the php file:
$chkpay = $row[0];
$resu2lt = mysql_query("SELECT * FROM skylines WHERE ownerid=$myid AND paidline='5'");
$num_rows = mysql_num_rows($resu2lt);
if ($num_rows >= 2) {
die("Error you have reached your limit of UNPAID new lines Click here to go back");
} else {
// generate name
$linename = $uname ."-". rand(0,9000);
// check if name is in use
$resu2lt = mysql_query("SELECT * FROM skylines WHERE ownerid=$myid AND lineuser='$linename'");
$num_rows = mysql_num_rows($resu2lt);
if ($num_rows == 1) {
$linename = $uname ."-". rand(0,90000);
// check if name is in use again
$resu2lt = mysql_query("SELECT * FROM skylines WHERE ownerid=$myid AND lineuser='$linename'");
$num_rows = mysql_num_rows($resu2lt);
if ($num_rows == 1) {
$linename = $uname ."-". rand(0,900000);
} }
$linepass = rand(100,9000000);
$linestart = date("d-m-Y");
$lineexpire = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"));
mysql_query("INSERT INTO skylines (ownerid, lineuser, linepass, startdate, expiredate, linestatus, linetest, paidline)
VALUES
('$myid', '$linename', '$linepass', '$linestart', '$lineexpire', 'New-Line', '3', '5')");
Hope my description of the what it should be doing what it is doing makes sense so if you can help me please if you can tell me what the error is and how to fix it that would be fantasic. I can't change the datebase names so needs a work a round please.
Thank you