---
title: "Lite problem... Query was empty..."
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/16005-lite-problem-query-was-empty"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "BeaR123"
published: "2001-08-19T14:55:00.000Z"
updated: "2001-08-19T16:11:00.000Z"
replies: 2
views: 163
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/16005-lite-problem-query-was-empty"
---

# Lite problem... Query was empty...

## #1 — BeaR123, 2001-08-19T14:55Z

Denna koden ska uppdatera en row eller skapa en ny.

```
$sql_update = "UPDATE tabellen SET visningar=visningar + 1 WHERE id=1";
mysql_query("$sql");
if (mysql_affected_rows() == 0)
$sql_insert = "INSERT INTO tabellen(ID, Namn, Visningar) VALUES(1,'start',1)";
mysql_query("$sql_insert");
```

Ingen row skappades eller uppdaterades men jag fick det här felet:
**MySQL-Error: Query was empty**

Permalänk: https://www.webforum.nu/p/16005

## #2 — Kim, 2001-08-19T15:39Z

Testa att ändra if-satsen till följande

```
if (mysql_affected_rows() == -1)
```

Permalänk: https://www.webforum.nu/p/320260

## #3 — LarsG, 2001-08-19T16:11Z

Testa att ändra till

```
$sql_update = "UPDATE tabellen SET visningar=visningar + 1 WHERE id=1";
mysql_query("$sql[b]_update[/b]");
if (mysql_affected_rows() <= 0) [b]{[/b]
$sql_insert = "INSERT INTO tabellen(ID, Namn, Visningar) VALUES(1,'start',1)";
mysql_query("$sql_insert");
[b]}[/b]
```

Permalänk: https://www.webforum.nu/p/320261

---

Tråden på webben: https://www.webforum.nu/amne/php/16005-lite-problem-query-was-empty
