Exemple #1
0
<?php

include '../../config/config.php';
$xml = new DOMDocument("1.0", "utf-8");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->Load('../../data/tags.xml');
// $sql = "SELECT Auto_increment FROM information_schema.tables WHERE table_name='tbltag'";
// $query = mysqli_query($conn, $sql);
// $result = mysqli_fetch_row($query);
$name = $_POST['tag_name'];
$stmt = $conn->prepare("INSERT INTO tbltag (tag_name) VALUES(?)");
$stmt->bind_param("s", $name);
$stmt->execute();
$id = mysqli_insert_id($conn);
$new_tag = $xml->createElement("tag");
$new_tag->appendChild($xml->createElement('id', $id));
$new_tag->appendChild($xml->createElement('name', $name));
$xml->getElementsByTagName('tags')->item(0)->appendChild($new_tag);
$xml->Save('../../data/tags.xml');
header('Location: ../tag_list.php');
    $category_id = $_POST['category_id'];
    $category_name = $_POST['category_name'];
    $category_details = $_POST['category_details'];
    // update record from database
    $sql = "UPDATE tblcategory set category_name ='" . $category_name . "',category_details ='" . $category_details . "' WHERE category_id = '" . $category_id . "' LIMIT 1";
    $conn->query($sql);
    if ($conn->query($sql)) {
        $xml = new DOMDocument("1.0", "utf-8");
        $xml->formatOutput = true;
        $xml->preserveWhiteSpace = false;
        $xml->Load('../../data/category.xml');
        $root = $xml->getElementsByTagName('categories')->item(0);
        $categories = $root->getElementsByTagName('category');
        foreach ($categories as $category) {
            if ($category->getElementsByTagName('id')->item(0)->nodeValue == $category_id) {
                $category->getElementsByTagName('name')->item(0)->nodeValue = $category_name;
                $category->getElementsByTagName('details')->item(0)->nodeValue = $category_details;
            }
        }
        $xml->Save('../../data/category.xml');
        $return = array("status" => "200", "message" => "Success");
        echo json_encode($return);
    } else {
        echo "ERROR: could not prepare SQL statement.";
    }
    $conn->close();
    // redirect user after delete is successful
    // header("Location: ../category_list.php");
} else {
    // header("Location: ../category_list.php");
}
Exemple #3
0
$stmt = $conn->prepare("INSERT INTO tblproduct (product_name,category_id,description,quantity,price,product_image) VALUES(?,?,?,?,?,?)");
$stmt->bind_param("ssssss", $name, $category, $description, $quantity, $price, $product_image);
$stmt->execute();
$id = mysqli_insert_id($conn);
include '../../config/config.php';
$tag_names = str_replace(array('[', ']'), '', implode("','", $tags_array_string));
$sql = "SELECT tag_id FROM tbltag WHERE tag_name IN ({$tag_names})";
$query = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($query)) {
    $tags_array_id[] = $row['tag_id'];
}
$tags_sql = '';
foreach ($tags_array_id as &$tag_id) {
    $tags_sql .= "INSERT INTO tblproduct_tag (product_id, tag_id, category_id) \n\t  \t\t\t\tVALUES ('" . $id . "','" . $tag_id . "','" . $category . "');";
    //SAVE EACH ITEMS IN THE PRODUCT TAG TABLE
}
$conn->multi_query($tags_sql);
$conn->close();
//====================== XML INTEGRATION
$new_product = $xml->createElement("product");
$new_product->appendChild($xml->createElement('id', $id));
$new_product->appendChild($xml->createElement('name', $name));
$new_product->appendChild($xml->createElement('description', $description));
$new_product->appendChild($xml->createElement('quantity', $quantity));
$new_product->appendChild($xml->createElement('price', $price));
$new_product->appendChild($xml->createElement('image', $product_image));
$new_product->appendChild($xml->createElement('category', $category));
$xml->getElementsByTagName('products')->item(0)->appendChild($new_product);
$xml->Save('../../data/products.xml');
header('Location: ../products_list.php');
$return = array("status" => "200", "message" => "Success");
        // CREATE AN XML DATA
        $xml = new DOMDocument("1.0", "utf-8");
        $xml->formatOutput = true;
        $xml->preserveWhiteSpace = false;
        $xml->Load('data/users.xml');
        $new_user = $xml->createElement("user");
        $new_user->appendChild($xml->createElement('id', $id));
        $new_user->appendChild($xml->createElement('firstname', $firstName));
        $new_user->appendChild($xml->createElement('middlename', $middleName));
        $new_user->appendChild($xml->createElement('lastname', $lastName));
        $new_user->appendChild($xml->createElement('contact', $contact));
        $new_user->appendChild($xml->createElement('address', $address));
        $new_user->appendChild($xml->createElement('email', $email1));
        $new_user->appendChild($xml->createElement('birthdate', $birthdate));
        $xml->getElementsByTagName('users')->item(0)->appendChild($new_user);
        $xml->Save('data/users.xml');
        // =============================
        $registerMessage = "Your have successfully created a new account.<br><a href='index.php'>Log In </a>";
        $_SESSION['registerMessage'] = $registerMessage;
    }
    // header('Location: /index.php/#login');
}
$_SESSION['captcha'] = rand(1000, 9999);
?>

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body class="register-wrapper">
Exemple #5
0
    $id = $_GET['id'];
    // delete record from database
    if ($stmt = $conn->prepare("DELETE FROM tbluser WHERE userID = ? LIMIT 1")) {
        $stmt->bind_param("s", $id);
        $stmt->execute();
        $stmt->close();
        $return = array("status" => "200", "message" => "Success");
        echo json_encode($return);
        // delete to XML FILE
        $xml = new DOMDocument("1.0", "utf-8");
        $xml->formatOutput = true;
        $xml->preserveWhiteSpace = false;
        $xml->Load('../../data/users.xml');
        $root = $xml->getElementsByTagName('users')->item(0);
        $users = $root->getElementsByTagName('user');
        foreach ($users as $user) {
            $current_id = $user->getElementsByTagName('id')->item(0)->nodeValue;
            if ($current_id == $id) {
                $root->removeChild($user);
            }
        }
        $xml->Save('../../data/users.xml');
    } else {
        echo "ERROR: could not prepare SQL statement.";
    }
    $conn->close();
    // redirect user after delete is successful
    // header("Location: ../user_list.php");
} else {
    // header("Location: ../user_list.php");
}