Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require("config.php");
- if (!empty($_POST)) {
- //initial query
- $query = "SELECT nama, alamat, email, status FROM `tblpengguna` WHERE username=:user";
- $query_params = array(
- ':user' => $_POST['username']
- );
- //execute query
- try {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch (PDOException $ex) {
- $response["sukses"] = 0;
- $response["pesan"] = "Database Error!";
- die(json_encode($response));
- }
- // Finally, we can retrieve all of the found rows into an array using fetchAll
- $rows = $stmt->fetchAll();
- if ($rows) {
- $response["sukses"] = 1;
- $response["pesan"] = "Profil tersedia!";
- $response["profil"] = array();
- foreach ($rows as $row) {
- $post = array();
- $post["nama"] = $row["nama"];
- $post["alamat"] = $row["alamat"];
- $post["email"] = $row["email"];
- $post["status"] = $row["status"];
- //update our repsonse JSON data
- array_push($response["profil"], $post);
- }
- // echoing JSON response
- echo json_encode($response);
- } else {
- $response["sukses"] = 0;
- $response["profil"] = "Profil tidak tersedia!";
- die(json_encode($response));
- }
- } else {
- ?>
- <h1>Lihat Profil</h1>
- <form action="profil.php" method="post">
- Nama Pengguna:<br />
- <input type="text" name="username" placeholder="username" />
- <br /><br />
- <input type="submit" value="Lihat Profil" />
- </form>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement