GroundApps / ShoppingList_Backend

Simple Centralized Shoppinglist - php backend
GNU General Public License v3.0
27 stars 23 forks source link

"Multiple items deleted" not showing up #46

Closed morpheus000 closed 8 years ago

morpheus000 commented 8 years ago

Message "Multiple items deleted" not showing up using mysql and Shoppingslist 1.3, list must be synced to make the deleted items vanish.

J-8 commented 8 years ago

That is weird as nothing was changed. I will look into it when I get home later today.

J-8 commented 8 years ago

Does this happen when you clear the whole list or only some of the items?

morpheus000 commented 8 years ago

happens in both cases, maybe its something in my setup. 1.3 is the first Version i´ve tested with MySQL so far. i will check an earlier Version.

morpheus000 commented 8 years ago

i tested it with backend v1.0 <- shoppinglist v1.3 and it´s the same.

J-8 commented 8 years ago

I checked it and you are right. There is an exclamation mark in line 102 of mysql_connector.php that should not be there.

function deleteMultiple($jsonData)
            {
                if(empty($jsonData)) {
                    die(json_encode(array('type' => API_ERROR_MISSING_PARAMETER, 'content' => 'parameter missing for deleteMultiple')));
                }
            //connect to db
            $handler = new mysqli($this->server, $this->username, $this->password, $this->database);

            //check if connection successful
            if ($handler->connect_error) {
                die(json_encode(array('type' => API_ERROR_DATABASE_CONNECT, 'content' => $handler->connect_error)));
            }
            //iterate over all items in json array
            $array = json_decode( $jsonData, true );
            foreach($array as $item)
            {
                //prepare query
                $stmt = $handler->prepare("DELETE from ShoppingList WHERE item = ?");
                $stmt->bind_param('s', $item['itemTitle']);

                //execute query and check if successful
                if (!$stmt->execute()){
                    $result = json_encode(array('type' => API_SUCCESS_DELETE, 'content' => ' Multiple items deleted'));
                } else {
                    $result = json_encode(array('type' => API_ERROR_DELETE, 'content' => $stmt->error));
                }
            }

Change

if (!$stmt->execute()){ 

to

if ($stmt->execute()){ 

and it works.

Please report back if that fixes it. Thanks!

morpheus000 commented 8 years ago

yes fixed it for me :) great work, keep it up!

J-8 commented 8 years ago

Glad to hear that:)