Hey guys... I'm about to pull my hair out here; I've got the code below & I'm sure you can see what it is supposed to do.... but instead of making a new entry with the number "1" in the record or adding +1 to the current result it is adding pretty much what it feels like... sometimes it makes a record starting with the number 2 or 3 or even 4... it even adds on the amounts also.
I have no idea why this is happening.....
if ($search_method == "title") {
mysql_connect($dbhost, $dbuser, $dbpass) or die("Couldn't connect to server.");
@mysql_select_db($dbname) or die("Couldn't connect to database.");
$fquery="SELECT id,amount FROM no_results WHERE type='title' AND term='$terms' LIMIT 1";
$fsql=mysql_query($fquery);
$fnum=mysql_num_rows($fsql);
$frow=mysql_fetch_row($fsql);
if ($fnum > 0) {
// Add to amount
$new_amount = $frow[1] + 1;
$fquery="UPDATE no_results SET amount='$new_amount' WHERE id='$frow[0]' LIMIT 1";
mysql_query($fquery);
} else {
// Add new record
$fquery="INSERT INTO no_results(term,type,amount) VALUE('$terms','title','1')";
mysql_query($fquery);
}
mysql_close();
} elseif ($search_method == "artist") {
mysql_connect($dbhost, $dbuser, $dbpass) or die("Couldn't connect to server.");
@mysql_select_db($dbname) or die("Couldn't connect to database.");
$fquery="SELECT id,amount FROM no_results WHERE type='artist' AND term='$terms' LIMIT 1";
$fsql=mysql_query($fquery);
$fnum=mysql_num_rows($fsql);
$frow=mysql_fetch_row($fsql);
if ($fnum > 0) {
// Add to amount
$new_amount = $frow[1] + 1;
$fquery="UPDATE no_results SET amount='$new_amount' WHERE id='$frow[0]' LIMIT 1";
mysql_query($fquery);
} else {
// Add new record
$fquery="INSERT INTO no_results(term,type,amount) VALUE('$terms','artist','1')";
mysql_query($fquery);
}
mysql_close();
}
Also,
When I remove the $terms variable from the input & instead input a word directly it will insert the record correctly with the correct "1" result; however, it will make duplicate records... so instead of making one record it will make 2 duplicate records...
I echoed out my SQL statement of the INSERT & the output I got was "1".