Tuesday, 7 July 2015

Get SQL Data using PHP and Display using HTML

getSqlData.php

<?php
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");

    $conn = new mysqli("localhost", "root", "root", "World");
    $result = $conn->query("SELECT Code, Name, Region FROM Country");

    $outp = "[";
    while($rs = $result->fetch_array(MYSQLI_ASSOC))
    {
        if ($outp != "[")
            $outp .= ",";
       
        $outp .= '{"Code":"'. $rs["Code"] . '",';
        $outp .= '"Name":"' . $rs["Name"] . '",';
        $outp .= '"Region":"' . $rs["Region"] . '"}';
    }
    $outp .="]";

    $conn->close();
    echo($outp);
?>



index.html
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <div id="id01"></div>
        <script>
            var xmlhttp = new XMLHttpRequest();
            var url = "http://localhost/SampleWebSite/getSqlData.php";
            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    myFunction(xmlhttp.responseText);
                   
            }
            xmlhttp.open("GET", url, true);
            xmlhttp.send();
            function myFunction(response)
            {
                var arr = JSON.parse(response);
                var i;
                var out = "<table>";
                for(i = 0; i < arr.length; i++)
                {
                    out += "<tr>"+
                                "<td>" + arr[i].Code + "</td>" +
                                "<td>" + arr[i].Name + "</td>" +
                                "<td>" + arr[i].Region + "</td>"+
                            "</tr>";
                }
                out += "</table>";
                document.getElementById("id01").innerHTML = out;
            }
        </script>
    </body>
</html>



Sunday, 5 July 2015

No 'Access-Control-Allow-Origin' Header is Present on the Requested Resource

Add the following headers to the HTML file:

<!DOCTYPE html>
<html>
   <head>

      <?php
          header('Access-Control-Allow-Origin: *');
          header('Access-Control-Allow-Methods: GET, POST');
      ?>
.
.
.



Call PHP Method with Parameter from HTML

 <?php
     if (isset($_POST['getData']) and isset($_POST['country']))
     {       
        $servername = "localhost";
        $username = "root";
        $password = "root";
        $dbname = "World";

        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);

        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }
        $sql = "SELECT code, name FROM country where name='" .  $_POST['country'] . "';";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo $row["code"]. " - " . $row["name"]. "<br>";
            }
        } else {
            echo "0 results";
        }
        $conn->close();
    }
?>


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>

       <form action="" method="post">
           Country: <input type="text" name="country">
           <input type="submit" name ="getData" value="send"></input>
        </form>

    </body>
</html>

Tuesday, 23 June 2015

Receive Yahoo Emails in Outlook 2013 using IMAP

  1. File > Add Account
  2. Manual setup or additional server types > Next
  3. IMAP > Next
  4. Account Settings:
    • Your Name: name show when sending email
    • Email address: Yahoo Mail address
    • Account Type: IMAP
    • Server information: match the Yahoo Mail IMAP settings
    • User Name: Yahoo ID
    • Password: Yahoo account password
    • Require logon using Secure Password Authentication: OFF
  5. More Settings > Outgoing Server tab
    • My outgoing server (SMTP) requires authentication: ON
    • Use same settings as my incoming mail server: ON
  6. Advanced tab settings:
    • Incoming server (POP3) 
      • imap.mail.yahoo.com
      • port: 993 
      • encrypted connection: SSL
    • Outgoing server (SMTP) 
      • smtp.mail.yahoo.com
      • port: 587 
      • encryption type: TLS
  7. Restart Outlook
  8. Send/Receive All Folders to sync


Tuesday, 3 February 2015

C# and JQuery Mobile Login Popup Form

DEFAULT.ASPX

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head runat="server">
  4.     <title></title>
  5.     <meta name="viewport" content="width=device-width, initial-scale=1" />
  6.     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
  7.     <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
  8.     <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  9.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  10.    
  11.     <script>
  12.         function runme() {
  13.             $.ajax({
  14.                 type: "POST",
  15.                 url: "default.aspx/checkLogin",
  16.                 contentType: "application/json; charset=utf-8",
  17.                 data: "{'username':'" + $('#un').val() + "','password':'" + $('#pw').val() + "'}",
  18.                 dataType: "json",
  19.                 success: function (response) {
  20.                     var names = response.d;
  21.                     alert(names);                   
  22.                 },
  23.                 failure: function (response) {
  24.                     alert(response.d);
  25.                 }
  26.             });
  27.         }
  28.         </script>
  29. </head>
  30. <body>
  31.     <form id="form1" runat="server">
  32.         <a href="#popupLogin" data-rel="popup" data-position-to="window" data-role="button" data-inline="true" data-icon="check" data-theme="a" data-transition="pop">Sign in</a>
  33.         <div data-role="popup" id="popupMenu" data-theme="a">
  34.             <div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
  35.                 <div style="padding: 10px 20px;">
  36.                     <h3>Please sign in</h3>
  37.                     <label for="un" class="ui-hidden-accessible">Username:</label>
  38.                     <input name="user" id="un" value="" placeholder="username" data-theme="a" type="text" />
  39.                     <label for="pw" class="ui-hidden-accessible">Password:</label>
  40.                     <input name="pass" id="pw" value="" placeholder="password" data-theme="a" type="password" />
  41.                     <button data-theme="b" data-icon="check" onclick="runme()">Sign in</button>
  42.                 </div>
  43.             </div>
  44.         </div>
  45.     </form>
  46. </body>
  47. </html>



DEFAULT.ASPX.CS

  1. [WebMethod]
  2. public static string checkLogin(string username, string password)
  3. {
  4.     Dictionary<string, string> name = new Dictionary<string, string>();
  5.     name.Add(username, password);
  6.     string myJsonString = (new JavaScriptSerializer()).Serialize(name);
  7.     return myJsonString;
  8. }

Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link