Вы говорите, что структура вашей таблицы следующая:
id tag count
Это означает, что ваш текущий запрос не будет работать, если у вас нет tag
в качестве первичного ключа. Если это так, вы, вероятно, используете столбец id
в качестве первичного ключа.
Так что успокойся и просто проверь, есть ли уже тег.
Если это так, обновите счет. Если нет, добавьте его.
//--grab the tag
$tag = mysql_real_escape_string($_POST['tag']);
//--see if the tag already exists and potentially what the current count is
$query = "SELECT id, count FROM tags WHERE tag='$tag'";
$result = mysql_query($query);
//--if there is a row, that means the tag exists
if(mysql_num_rows($result))
{
//--pull out the tag ID and the current count and increment by one.
$tag_info = mysql_fetch_array($result);
$tag_info_id = $tag_info["id"];
$tag_info_count = $tag_info["count"] + 1;
//--update the table with the new count
$sql_update_cnt = "UPDATE tags SET count='$tag_info_count'
WHERE id='$tag_info_id'";
mysql_query($sql_update_cnt);
echo "$tag now with $tag_info_count instances";
}
else
{
//--tag is not there, so insert a new instance and 1 as the first count
$query = "INSERT INTO tags (tag, count) VALUES ('$tag', 1)";
mysql_query($query);
echo "1 record added";
}
mysql_close($dbc);