The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

MySQL INSERT error w/PHP-Fusion

NightslyrNightslyr Registered User regular
edited June 2007 in Help / Advice Forum
So, I'm using PHP-Fusion (for those 'not in the know,' it's a free content management system) as the foundation of a client's site. Because of their demands, I've had to both install addons (no big deal) and modify both the addons and original Fusion code, as well as create my own custom registration form in order to meet those demands. Nothing too difficult, but wading through Fusion's spaghetti code grows frustrating.

So, I'm at the point of testing my registration form with the database. I can get two somewhat complex INSERT queries to work, but the simple one keeps sending me an error, and it's driving me nuts.

The query in question is:
INSERT INTO fusion_aw_ec_events (ev_allow_logins) VALUES ('1') WHERE ev_id='11'

ev_allow_logins is just a simple TINYINT(1) column. ev_id, I believe, is just a SMALLINT(5) column.

The code I'm using to create and run this query is:
$query = "INSERT INTO ".DB_PREFIX."aw_ec_events (ev_allow_logins) VALUES ('1') WHERE ev_id='".$ev_id."'";
$result = dbquery($query);

dbquery() is a built-in Fusion function. It's nothing fancy:
function dbquery($query) {
	$result = @mysql_query($query);
	if (!$result) {
		echo mysql_error();
		return false;
	} else {
		return $result;
	}
}

That shouldn't be the cause of my error.

The error I keep getting is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ev_id='11'' at line 1

But I'm not seeing any syntax errors, unless you can't have a WHERE clause in an INSERT.

Any ideas?

Nightslyr on

Posts

  • scandalscandal Registered User regular
    edited June 2007
    INSERT is only if you're adding a new row to the table, based on your query it looks like you're trying to update an existing row. So,
    UPDATE fusion_aw_ec_events SET ev_allow_logins = 1 WHERE ev_id='11'
    

    I would highly recommend bookmarking the MySQL documentation so you can check the correct syntax of everything.

    scandal on
  • NightslyrNightslyr Registered User regular
    edited June 2007
    scandal wrote: »
    INSERT is only if you're adding a new row to the table, based on your query it looks like you're trying to update an existing row. So,
    UPDATE fusion_aw_ec_events SET ev_allow_logins = 1 WHERE ev_id='11'
    

    I would highly recommend bookmarking the MySQL documentation so you can check the correct syntax of everything.

    Ah, thanks man! :)

    Nightslyr on
Sign In or Register to comment.