function getProductes($id) { //Ens connectem a la base de dades require_once '../db_connect.php'; /*Creem la connexió*/ $db = new DB_CONNECT(); $con = $db->connect(); $productes = array(); $sql = "SELECT * FROM nfc_producte WHERE Id_categoria='{$id}'"; $query = mysqli_query($con, $sql); while ($producte = mysqli_fetch_assoc($query)) { $productes[] = $producte; } return json_encode($productes); $db->close($con); }
function getAllCategories() { //Ens connectem a la base de dades require_once 'db_connect.php'; /*Creem la connexió*/ $db = new DB_CONNECT(); $con = $db->connect(); $categories = array(); $sql = "SELECT * FROM nfc_categoria ORDER BY id_categoria"; $query = mysqli_query($con, $sql); while ($categoria = mysqli_fetch_assoc($query)) { $categories[] = $categoria; } return json_encode($categories); $db->close($con); }
<?php require_once __DIR__ . '/db_connect.php'; $db = new DB_CONNECT(); $output['deals'] = array(); $db->connect(); $q = mysql_query("SELECT * from deals"); while ($row = mysql_fetch_array($q)) { $temp = array(); $temp['id'] = $row['id']; $temp['name'] = $row['name']; $temp['desc'] = $row['description']; $temp['expire_time'] = $row['expire_time']; $temp['brand_id'] = $row['brand_id']; $temp['img'] = $row['image']; array_push($output['deals'], $temp); } header('Content-Type: application/json'); print json_encode($output); mysql_close();
/*test data * $username = '******'; * $email = '*****@*****.**'; * $password = '******'; */ // check for required fields if (isset($_POST["username"]) && isset($_POST["email"]) && isset($_POST["password"]) && (!empty($_POST["username"]) && !empty($_POST["email"]) && !empty($_POST["password"]))) { $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password"]; $date = date("Y-d-m"); // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); $connection = $db->connect(); // mysql inserting a new row $result = mysqli_query($connection, "INSERT INTO user(username, email, password,date_joined) VALUES('{$username}', '{$email}', '{$password}','{$date}')"); $userId = mysqli_insert_id($connection); // check if row inserted or not if ($result) { // successfully inserted into database $response["userId"] = $userId; $response["success"] = 1; $response["message"] = "user registered successfully."; // echoing JSON response echo json_encode($response); } else { // failed to insert row $response["success"] = 0; $response["message"] = "Oops! An error occurred.";
<?php //make database connection require_once __DIR__ . '/db_connect.php'; $db = new DB_CONNECT(); $conn = $db->connect(); //initializing response array $response = array(); //default city value for testing web without android post $cityRetrived = "toronto"; //get post data city if (isset($_GET["city"])) { $cityRetrived = $_GET['city']; require_once __DIR__ . '/APICalls.php'; //sql query for current conditions $result2 = $conn->query("SELECT * FROM `currentConditions` WHERE city = '{$cityRetrived}'"); //check for empty data if (!empty($result2)) { if ($result2->num_rows > 0) { //getting row array from database $result2 = mysqli_fetch_array($result2); //storing row into data arrary $data = array(); $data["city"] = $result2["city"]; $data["temp"] = $result2["temp"]; $data["apparantTemp"] = $result2["apparantTemp"]; $data["summary"] = $result2["summary"]; $data["icon"] = $result2["icon"]; $data["time"] = $result2["time"]; $data["pressure"] = $result2["pressure"]; $data["dewPoint"] = $result2["dewPoint"];
function getTaulaProductsCarrito() { session_start(); $productes_afegits = array(); $carrito = "<table id=\"taula_carrito\">"; $array_productes = explode(",", $_SESSION['carro']); $carrito .= "<tr>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula header_taula\">IMATGE</p>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula header_taula\">NOM</p>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula header_taula\">PREU (c/u)</p>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula header_taula\">PREU TOTAL</p>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula header_taula\">MODIFICAR</p>"; $carrito .= "</td>"; $quantitat_productes = 0; $preu_total = 0; foreach ($array_productes as $producte) { if ($producte != "") { $id_producte = substr($producte, 0, strpos($producte, "/")); $id_producte = trim($id_producte, "["); if (!in_array($id_producte, $productes_afegits)) { //Ens connectem a la base de dades require_once '../db_connect.php'; /*Creem la connexió*/ $db = new DB_CONNECT(); $con = $db->connect(); $sql = "SELECT * FROM nfc_producte WHERE id_producte = " . $id_producte . ";"; $query = mysqli_query($con, $sql) or die(mysqli_error($con)); $row = mysqli_fetch_array($query); $carrito .= "<tr>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<img class=\"element_taula\" width=\"100\" height=\"100\" src=\"../" . $row["URL_imatge"] . "\" onclick=\"removeFromCart(" . $id_producte . ")\"/>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $nom_producte = substr($producte, strpos($producte, "/") + 1, strpos($producte, "]")); $nom_producte = trim($nom_producte, "]"); $carrito .= "<p class=\"element_taula\">" . $nom_producte . " (x" . count(preg_grep($producte, $array_productes)) . ")</p>"; $productes_afegits[] = $id_producte; $carrito .= "</td>"; $quantitat_productes += count(preg_grep($producte, $array_productes)); $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula\">" . $row["Preu_IVA"] . "</p>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula\">" . $row["Preu_IVA"] * count(preg_grep($producte, $array_productes)) . "</p>"; $carrito .= "</td>"; $preu_total += $row["Preu_IVA"] * count(preg_grep($producte, $array_productes)); $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<img class=\"element_taula\" src=\"../resources/img/delete-product.png\" onclick=\"borrar(" . $id_producte . ");\"/>"; $carrito .= "</td>"; $carrito .= "</tr>"; } } } $carrito .= "<tr>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula header_taula\">TOTAL</p>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula\">" . $quantitat_productes . " unitats</p>"; $carrito .= "</td>"; $carrito .= "<td>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<p class=\"element_taula\">" . $preu_total . " euros</p>"; $carrito .= "</td>"; $carrito .= "<td id=\"fila_carrito\">"; $carrito .= "<button class=\"element_taula\">CONFIRMAR</button>"; $carrito .= "</td>"; $carrito .= "</table>"; return $carrito; }
<?php // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $db = new DB_CONNECT(); // get all products from products table $result = mysqli_query($db->connect(), "SELECT *FROM spt_user where userid=\"" . $_POST["userId"] . "\""); // check for empty result if (mysqli_num_rows($result) > 0) { // looping through all results // products node while ($row = mysqli_fetch_array($result)) { $response["username"] = $row["username"]; } // success $response["success"] = 1; // echoing JSON response echo json_encode($response); } else { $response["success"] = 0; $response["message"] = "No persons found"; echo json_encode($response); }
$response["errors"] = array(); if (isset($_POST["url"])) { if (preg_match('/\\s/', $_POST["url"])) { } require_once __DIR__ . '/db_connect.php'; $_ID = $_SESSION["session_name"]; $url = $_POST["url"]; if ($url == "./maps" || $url == "./vizs") { $response["success"] = 1; $response["redirect"] = "./modules/" . stripslashes($url); echo json_encode($response); exit; } // $url=addslashes($url); $db = new DB_CONNECT(); $db_c = $db->connect("userdata"); if ($url == "./p2p_ecommerce") { $qry = $db_c->prepare("SELECT * from hw_users where user_id=?"); // fist argument tells format of each parameter $qry->bind_param("s", $_ID); $qry->execute(); $result = $qry->get_result(); // echo $_ID; if (mysqli_num_rows($result) == 1) { $row = mysqli_fetch_array($result); if ($row['isadmin'] == 1) { $_SESSION['hw_user_chk'] = 1; } } } $qry = $db_c->prepare("SELECT * from registered_modules where user_id=? AND module_id=?");
<?php /* * Following code will list all the items */ // array for JSON response $response = array(); if (isset($_GET["sub_cat_id"])) { $sub_cat_id = $_GET["sub_cat_id"]; // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); // get all items from item table $result = mysqli_query($db->connect(), "SELECT *FROM item WHERE sub_category = '{$sub_cat_id}' ORDER BY RAND()") or die(mysql_error()); // check for empty result if (mysqli_num_rows($result) > 0) { // looping through all results // item node $response["items"] = array(); while ($row = mysqli_fetch_array($result)) { // temp user array $item = array(); $item["idItem"] = $row["idItem"]; $item["sub_category"] = $row["sub_category"]; $item["shop"] = $row["shop"]; $item["user"] = $row["user"]; $item["item_name"] = $row["item_name"]; $item["price"] = $row["price"]; $item["item_image"] = $row["item_image"]; $item["item_description"] = $row["description"];
<?php $_POST = json_decode(file_get_contents('php://input'), true); if (isset($_POST["email"]) && isset($_POST['text'])) { require_once __DIR__ . './db_connect.php'; $id = $_POST["email"]; $tweet = $_POST['text']; //./db_connect file has class $db = new DB_CONNECT(); $db_c = $db->connect(); $qry = $db_c->prepare("INSERT INTO tweets(idtemail,tweet) VALUES (?,?)"); // fist argument tells format of each parameter $qry->bind_param("ss", $id, $tweet); $qry->execute(); $qry->close(); $db_c->close(); } else { echo "POST ELEMENTS NOT SET!"; }
<?php /* * Following code will list all the items */ // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); // get all items from item table $result = mysqli_query($db->connect(), "SELECT *FROM item ORDER BY RAND()") or die(mysql_error()); // check for empty result if (mysqli_num_rows($result) > 0) { // looping through all results // item node $response["items"] = array(); while ($row = mysqli_fetch_array($result)) { // temp user array $item = array(); $item["idItem"] = $row["idItem"]; $item["sub_category"] = $row["sub_category"]; $item["category"] = $row["category"]; $item["shop"] = $row["shop"]; $item["user"] = $row["user"]; $item["item_name"] = $row["item_name"]; $item["price"] = $row["price"]; $item["item_image"] = $row["item_image"]; // push single product into final response array array_push($response["items"], $item);
<?php /* * Following code will list all the items */ // array for JSON response $response = array(); if (isset($_GET["sub_cat_id"]) && isset($_GET["item_id"])) { $sub_cat_id = $_GET["sub_cat_id"]; $item_id = $_GET["item_id"]; // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); // get all items from item table $result = mysqli_query($db->connect(), "SELECT *FROM item WHERE sub_category = '{$sub_cat_id}' AND idItem NOT IN ('{$item_id}') ORDER BY RAND() LIMIT 6") or die(mysql_error()); // check for empty result if (mysqli_num_rows($result) > 0) { // looping through all results // item node $response["items"] = array(); while ($row = mysqli_fetch_array($result)) { // temp user array $item = array(); $item["idItem"] = $row["idItem"]; $item["sub_category"] = $row["sub_category"]; $item["shop"] = $row["shop"]; $item["user"] = $row["user"]; $item["item_name"] = $row["item_name"]; $item["price"] = $row["price"]; $item["item_image"] = $row["item_image"];
<?php /* * Following code will list all the items */ // array for JSON response $response = array(); if (isset($_GET["cat_id"])) { $cat_id = $_GET["cat_id"]; // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); // get all items from item table $result = mysqli_query($db->connect(), "SELECT *FROM sub_category WHERE Category_idCategory= '{$cat_id}'") or die(mysql_error()); // check for empty result if (mysqli_num_rows($result) > 0) { // looping through all results // item node $response["sub_category"] = array(); while ($row = mysqli_fetch_array($result)) { // temp user array $sub_category = array(); $sub_category["idSub_category"] = $row["idSub_category"]; $sub_category["sub_category_name"] = $row["sub_category_name"]; $sub_category["sub_cat_image"] = $row["sub_cat_image"]; // push single product into final response array array_push($response["sub_category"], $sub_category); } // success $response["success"] = 1;
<?php /* * Following code will list all the items */ // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); // get all items from item table $result = mysqli_query($db->connect(), "SELECT *FROM category") or die(mysql_error()); // check for empty result if (mysqli_num_rows($result) > 0) { // looping through all results // item node $response["category"] = array(); while ($row = mysqli_fetch_array($result)) { // temp user array $category = array(); $category["idCategory"] = $row["idCategory"]; $category["category_name"] = $row["category_name"]; $category["cat_image"] = $row["cat_image"]; // push single product into final response array array_push($response["category"], $category); } // success $response["success"] = 1; // echoing JSON response echo json_encode($response);
<?php $response = array(); if (isset($_GET['id_user'])) { require '..\\db_connect.php'; $db = new DB_CONNECT(); $mysqli = $db->connect(); $id_user = $_GET['id_user']; $result = $mysqli->query("SELECT *FROM purchase_history WHERE ID_USER= '******' ") or die(mysql_error()); if (mysqli_num_rows($result) > 0) { $response["purchase_history"] = array(); while ($row = mysqli_fetch_array($result)) { $history = array(); $history["ID"] = $row["ID"]; $history["ID_PRODUCT"] = $row["ID_PRODUCT"]; array_push($response["purchase_history"], $history); } $response["success"] = 1; echo json_encode($response); } else { $response["success"] = 0; $response["message"] = "No products found"; echo json_encode($response); } }
/* * Following code will get single item details * An item is identified by item id (idItem) */ // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); // check for post data if (isset($_GET["itemid"])) { $idItem = $_GET["itemid"]; // get a product from products table $result = mysqli_query($db->connect(), "SELECT *FROM item WHERE idItem = {$idItem}"); if (!empty($result)) { // check for empty result if (mysqli_num_rows($result) > 0) { $result = mysqli_fetch_array($result); $item = array(); $item["idItem"] = $result["idItem"]; $item["sub_category"] = $result["sub_category"]; $item["shop"] = $result["shop"]; $item["user"] = $result["user"]; $item["item_name"] = $result["item_name"]; $item["price"] = $result["price"]; $item["item_image"] = $result["item_image"]; $item["description"] = $result["description"]; // success $response["success"] = 1;
<?php $name = $_GET['name']; //$name = "Aster Hotel"; $response = array(); //echo $name; // include db connect class require_once __DIR__ . '/db_user_connect.php'; // connecting to db $con = new DB_CONNECT(); $con->connect(); //$sql ="SELECT category.catid, category.name as cat_name, information.id, information.name as info_name, information.* FROM category INNER JOIN information ON category.catid=information.cat_id WHERE information.name='$name'"; $sql = "SELECT category.catid, category.name as cat_name, information.id, information.name as info_name FROM category INNER JOIN information ON category.catid=information.cat_id WHERE information.name='{$name}'"; //echo $sql; $res = mysqli_query($con->myconn, $sql); $row = mysqli_num_rows($res); $row = mysqli_fetch_assoc($res); $table_name = $row['cat_name']; //echo $table_name; $sql = "SELECT {$table_name}.* , information.* FROM {$table_name} INNER JOIN information ON {$table_name}.info_id=information.id WHERE information.name='{$name}'"; //echo $sql; $res = mysqli_query($con->myconn, $sql); $row = mysqli_num_rows($res); if ($row > 0) { //echo "OL"; $response["detail"] = array(); while ($row = mysqli_fetch_assoc($res)) { //hotel (cat name_ $detail = array(); $detail["price_high"] = $row['price_high']; $detail["price_low"] = $row['price_low'];
$response = array(); /*test data * $username = '******'; * $email = '*****@*****.**'; * $password = '******'; */ // check for required fields if (isset($_POST["email"]) && isset($_POST["password"]) && (!empty($_POST["email"]) && !empty($_POST["password"]))) { $email = $_POST["email"]; $password = $_POST["password"]; // include db connect class require_once __DIR__ . '/php_includes/DB_CONNECT.php'; // connecting to db $db = new DB_CONNECT(); // mysql inserting a new row $result = mysqli_query($db->connect(), "SELECT idUser,email,password FROM user WHERE email = '{$email}' AND password = '******' LIMIT 1"); $count = mysqli_num_rows($result); if ($count > 0) { // successfully inserted into database $data = mysqli_fetch_array($result); $userId = $data['idUser']; $response["userId"] = $userId; $response["success"] = 1; $response["message"] = "user login successful"; // echoing JSON response echo json_encode($response); } else { // user login unsuccessful $response["success"] = 0; $response["message"] = "Oops! An error occurred"; // echoing JSON response