From fdd8d12320c8d7b4e73fe6216ffdffbb605e05c8 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Wed, 20 Aug 2014 15:05:35 +0200 Subject: [PATCH] Added remove element function --- c.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/c.php b/c.php index 3b3a0f0..3cd5ed6 100644 --- a/c.php +++ b/c.php @@ -153,6 +153,27 @@ $info = mysql_info(); echo $info ; } + + function removeElement($table, $headerJSON, $valuesJSON){ + $header = json_decode($headerJSON); + $values = json_decode($valuesJSON); + $query = "DELETE FROM `$table` WHERE ("; + + for($i = 0;$i < sizeof($header); $i++){ + $query .= "`".$header[$i]."` = '".$values[$i]."' "; + if($i+1!=sizeof($header)) + $query .= " AND "; + } + $query .= ");"; + + $result_id = mysql_query($query); + + if( !$result_id ){ + echo mysql_error(); + } else { + echo OK; + } + } } $action = $_GET['a']; @@ -217,6 +238,11 @@ $con->selectDb($database); $con->addElement($table, $header, $values); break; + case "removeelement": + $con->connect(); + $con->selectDb($database); + //print_r($_GET); + $con->removeElement($table, $header, $values); } $con->disconnect();