MySQL Query Processing order [RESOLVED]
Is it just me, or does MySQL seem to process queries in reverse order sometimes?
I have this script which i'm working on. What it does is check a database table for a specific username, and if the username doesn't exist in the database then it inserts that username as a new row. ie:
PHP Code:
...
if(strlen($_POST['username']) == 0)
$error[] = getString('profile_error_quote_blank');
else
{
$res = $db->sql_query("SELECT * FROM stocks WHERE quote LIKE \"$_POST[username]\" LIMIT 1");
if($db->sql_numrows($res) > 0)
$error[] = getString('quote_taken');
}
...
if(isset($error) && count($error) > 0)
{
require_once("stock_newform.inc.php");
}
else
{
if(getConfig('use_stock_verification') == 'N')
{
$sql = "INSERT INTO stocks (rootid,quote,name,email,url,joindate,region,country,type,description,keywords,pending) VALUES ('$mi[id]', '$username', '$name', '$email', '$website', '$jd', '$region', '$country', '$sector','$description','$keywords','N')";
$res = $db->sql_query($sql);
...
When I execute the script with what I know is a username that doesn't exist in the database, it displays the error '$error[] = getString('quote_taken');'. It seems to be that the 'INSERT INTO' query gets executed before the 'SELECT * FROM' query, and thus the new username is added to the table before the check is done to see if it exists. Is this normal?
I've never had this problem before, with other scripts that do this same type of error checking.
Windows NT 5.1 (HOME)
Apache Web Server 2.0.48 (Win32)
PHP 4.3.4
MySQL 4.1.0-alpha