Jump to content

Creating a new record and then updating it. What's wrong here?


facarroll

Recommended Posts

I have a snippet which only partly works. The code is intended to update a record, but if it does not exist, then create it. This snippet always creates a new record, and will not update an existing one. What's wrong?

$query = mysql_query("SELECT equip FROM topics WHERE equip = '$equip' AND managerId = '$userid'");
if (mysql_num_rows($query) > 0) {
mysql_query("UPDATE topics SET egroup1 = '$egroup1', egroup2 = '$egroup2', egroup3 = '$egroup3', egroup4 = '$egroup4', egroup5 = '$egroup5', egroup6 = '$egroup6',      WHERE equip = '$equip' AND managerId = '$userid'");
} else {
mysql_query("INSERT INTO topics (managerId, equip, title, url_big, url_small, egroup1, egroup2, egroup3, egroup4, egroup5, egroup6) 
    VALUES ('$userid','$wordquip', '$equip', '$bigpic', '$smallpic', '$egroup1', '$egroup2', '$egroup3', '$egroup4', '$egroup5', '$egroup6')");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.