En kontaktapplikation

Den ljusblå applikationen [källkod]

Kontaktapplikation

I denna övning så skall vi lära oss använda JSON, XML och stifta bekantskap med en ny databas, SQLite.

Vi kommer lära oss genom att skapa en applikation där vi lagrar kontakter med namn och maialdress, det är enkelt att bygga ut denna och lagra andra saker som adress, telefonnummer, kontaklänkar till facebook, twitter och vilka andra digitala tjänster som helst. Detta kan bli en egen uppgift för att träna mer.

Den tutorial som du skall följa hittar du här.

Lägg till kontakt

Lägg till kontakt

Namn
Epost

Tabellen med alla kontakter

contactIdnameemail
1 Johan Hällgren johan.hallgren.75@gmail.com
2 Peter peter@fossan.se
3

Samtliga variabler

Array
(
    [_GET] => Array
        (
        )

    [_POST] => Array
        (
        )

    [_COOKIE] => Array
        (
        )

    [_FILES] => Array
        (
        )

    [_SERVER] => Array
        (
            [PHPRC] => /storage/configuration/wrappers/83/218483/kursolle.se/php.ini
            [PHP_FCGI_CHILDREN] => 0
            [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
            [PWD] => /storage/configuration/wrappers/83/218483/kursolle.se
            [SHLVL] => 0
            [PHP_FCGI_MAX_REQUESTS] => 5000
            [SCRIPT_NAME] => /application/contact01/index.php
            [REQUEST_URI] => /application/contact01/
            [QUERY_STRING] => 
            [REQUEST_METHOD] => GET
            [SERVER_PROTOCOL] => HTTP/1.1
            [GATEWAY_INTERFACE] => CGI/1.1
            [REMOTE_PORT] => 45626
            [SCRIPT_FILENAME] => /storage/content/83/218483/kursolle.se/public_html/application/contact01/index.php
            [SERVER_ADMIN] => root@localhost
            [DOCUMENT_ROOT] => /storage/content/83/218483/kursolle.se/public_html
            [REMOTE_ADDR] => 54.224.17.157
            [SERVER_PORT] => 80
            [SERVER_ADDR] => 10.160.1.19
            [SERVER_NAME] => kursolle.se
            [SERVER_SOFTWARE] => Apache
            [SERVER_SIGNATURE] => 
            [HTTP_X_FORWARDED_FOR] => 54.224.17.157
            [HTTP_LOCAL_ADDR] => 195.74.38.121
            [HTTP_REMOTE_ADDR] => 54.224.17.157
            [HTTP_CONNECTION] => close
            [HTTP_IF_MODIFIED_SINCE] => Mon, 21 May 2018 16:44:39 GMT
            [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
            [HTTP_USER_AGENT] => CCBot/2.0 (http://commoncrawl.org/faq/)
            [HTTP_ACCEPT_ENCODING] => x-gzip, gzip, deflate
            [HTTP_HOST] => kursolle.se
            [FCGI_ROLE] => RESPONDER
            [PHP_SELF] => /application/contact01/index.php
            [REQUEST_TIME_FLOAT] => 1532346181.0109
            [REQUEST_TIME] => 1532346181
        )

    [_REQUEST] => Array
        (
        )

    [_ENV] => Array
        (
        )

    [GLOBALS] => Array
        (
            [_GET] => Array
                (
                )

            [_POST] => Array
                (
                )

            [_COOKIE] => Array
                (
                )

            [_FILES] => Array
                (
                )

            [_SERVER] => Array
                (
                    [PHPRC] => /storage/configuration/wrappers/83/218483/kursolle.se/php.ini
                    [PHP_FCGI_CHILDREN] => 0
                    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
                    [PWD] => /storage/configuration/wrappers/83/218483/kursolle.se
                    [SHLVL] => 0
                    [PHP_FCGI_MAX_REQUESTS] => 5000
                    [SCRIPT_NAME] => /application/contact01/index.php
                    [REQUEST_URI] => /application/contact01/
                    [QUERY_STRING] => 
                    [REQUEST_METHOD] => GET
                    [SERVER_PROTOCOL] => HTTP/1.1
                    [GATEWAY_INTERFACE] => CGI/1.1
                    [REMOTE_PORT] => 45626
                    [SCRIPT_FILENAME] => /storage/content/83/218483/kursolle.se/public_html/application/contact01/index.php
                    [SERVER_ADMIN] => root@localhost
                    [DOCUMENT_ROOT] => /storage/content/83/218483/kursolle.se/public_html
                    [REMOTE_ADDR] => 54.224.17.157
                    [SERVER_PORT] => 80
                    [SERVER_ADDR] => 10.160.1.19
                    [SERVER_NAME] => kursolle.se
                    [SERVER_SOFTWARE] => Apache
                    [SERVER_SIGNATURE] => 
                    [HTTP_X_FORWARDED_FOR] => 54.224.17.157
                    [HTTP_LOCAL_ADDR] => 195.74.38.121
                    [HTTP_REMOTE_ADDR] => 54.224.17.157
                    [HTTP_CONNECTION] => close
                    [HTTP_IF_MODIFIED_SINCE] => Mon, 21 May 2018 16:44:39 GMT
                    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                    [HTTP_USER_AGENT] => CCBot/2.0 (http://commoncrawl.org/faq/)
                    [HTTP_ACCEPT_ENCODING] => x-gzip, gzip, deflate
                    [HTTP_HOST] => kursolle.se
                    [FCGI_ROLE] => RESPONDER
                    [PHP_SELF] => /application/contact01/index.php
                    [REQUEST_TIME_FLOAT] => 1532346181.0109
                    [REQUEST_TIME] => 1532346181
                )

            [_REQUEST] => Array
                (
                )

            [_ENV] => Array
                (
                )

            [GLOBALS] => Array
 *RECURSION*
            [header] => <header>
	<p>En kontaktapplikation</p>
</header>
            [url] => kursolle.se/application/contact01/index.php
            [footer] => <footer>
	<p>&copy; Johan Hällgren</p>
	<p>Validera <a href="http://validator.w3.org/check?uri=kursolle.se/application/contact01/index.php" target="_blank">html</a> <a href="http://jigsaw.w3.org/css-validator/validator?profile=css3&amp;uri=kursolle.se/application/contact01/index.php" target="_blank">css</a></p>
</footer>
            [dbFileName] => contact.sqlite
            [dbFileAdress] => /storage/content/83/218483/kursolle.se/public_html/application/contact01/contact.sqlite
            [mess] => 
            [dbExists] => 1
            [db] => PDO Object
                (
                )

            [action] => 
            [sql] => SELECT * FROM contact ORDER BY contactId ASC;
            [stmt] => PDOStatement Object
                (
                    [queryString] => SELECT * FROM contact ORDER BY contactId ASC;
                )

            [result] => Array
                (
                    [0] => Array
                        (
                            [contactId] => 1
                            [name] => Johan H&auml;llgren
                            [email] => johan.hallgren.75@gmail.com
                        )

                    [1] => Array
                        (
                            [contactId] => 2
                            [name] => Peter
                            [email] => peter@fossan.se
                        )

                    [2] => Array
                        (
                            [contactId] => 3
                            [name] => 
                            [email] => 
                        )

                )

            [tableContacts] => <table><tr><th>contactId</th><th>name</th><th>email</th></tr>  <tr>
    <td>1</td>
    <td>Johan H&auml;llgren</td>
    <td>johan.hallgren.75@gmail.com</td>
  </tr>  <tr>
    <td>2</td>
    <td>Peter</td>
    <td>peter@fossan.se</td>
  </tr>  <tr>
    <td>3</td>
    <td></td>
    <td></td>
  </tr></table>
            [row] => Array
                (
                    [contactId] => 3
                    [name] => 
                    [email] => 
                )

            [formContacts] =>   <h2>Lägg till kontakt</h2>
  <form method="POST" action="?action=addContact">
  <fieldset>
    <legend>Lägg till kontakt</legend>
    <p>Namn <input type="text" name="name" required><br>
    Epost <input type="email" name="email" required><br>
    <input type="submit" value="Lägg till"></p>
  </fieldset>
  </form>
        )

    [header] => <header>
	<p>En kontaktapplikation</p>
</header>
    [url] => kursolle.se/application/contact01/index.php
    [footer] => <footer>
	<p>&copy; Johan Hällgren</p>
	<p>Validera <a href="http://validator.w3.org/check?uri=kursolle.se/application/contact01/index.php" target="_blank">html</a> <a href="http://jigsaw.w3.org/css-validator/validator?profile=css3&amp;uri=kursolle.se/application/contact01/index.php" target="_blank">css</a></p>
</footer>
    [dbFileName] => contact.sqlite
    [dbFileAdress] => /storage/content/83/218483/kursolle.se/public_html/application/contact01/contact.sqlite
    [mess] => 
    [dbExists] => 1
    [db] => PDO Object
        (
        )

    [action] => 
    [sql] => SELECT * FROM contact ORDER BY contactId ASC;
    [stmt] => PDOStatement Object
        (
            [queryString] => SELECT * FROM contact ORDER BY contactId ASC;
        )

    [result] => Array
        (
            [0] => Array
                (
                    [contactId] => 1
                    [name] => Johan H&auml;llgren
                    [email] => johan.hallgren.75@gmail.com
                )

            [1] => Array
                (
                    [contactId] => 2
                    [name] => Peter
                    [email] => peter@fossan.se
                )

            [2] => Array
                (
                    [contactId] => 3
                    [name] => 
                    [email] => 
                )

        )

    [tableContacts] => <table><tr><th>contactId</th><th>name</th><th>email</th></tr>  <tr>
    <td>1</td>
    <td>Johan H&auml;llgren</td>
    <td>johan.hallgren.75@gmail.com</td>
  </tr>  <tr>
    <td>2</td>
    <td>Peter</td>
    <td>peter@fossan.se</td>
  </tr>  <tr>
    <td>3</td>
    <td></td>
    <td></td>
  </tr></table>
    [row] => Array
        (
            [contactId] => 3
            [name] => 
            [email] => 
        )

    [formContacts] =>   <h2>Lägg till kontakt</h2>
  <form method="POST" action="?action=addContact">
  <fieldset>
    <legend>Lägg till kontakt</legend>
    <p>Namn <input type="text" name="name" required><br>
    Epost <input type="email" name="email" required><br>
    <input type="submit" value="Lägg till"></p>
  </fieldset>
  </form>
)