0

I am using JavaScript/HTML and a little bit of Jquery for a test app I am making using PhoneGap/Cordova.

What I would like to do is display the username on all pages once the user has signed in, I believe it is best to avoid using JavaScript and therefore I would ideally like to use PHP for this.

Can someone give me a helping hand here and tell me how to go about this?

Please see below different sections of my code that may be of help to you.

Login Function:

 function loginDB(tx)
         {
            var Username = document.getElementById("username").value;
          var Password = document.getElementById("password").value;
          tx.executeSql("SELECT * FROM SoccerEarth WHERE UserName='" + Username + "' AND Password= '" + Password + "'", [], renderList);

          }
         function renderList(tx,results) {
         if (results.rows.length > 0) {
           navigator.notification.alert("You are in!");
           $( ":mobile-pagecontainer" ).pagecontainer( "change", "#page4" );
         }
         else
         {
           navigator.notification.alert("Incorrect Password, Please try again!");
            $( ":mobile-pagecontainer" ).pagecontainer( "change", "#page3" );
         }
         }

HTML page example:

<div data-role="page" id="page4" data-theme="d">
<div data-role="header">
    <a href="#page1" class="ui-btn ui-icon-home ui-btn-icon-left">Sign Out</a>
    <h1>SoccerMeet</h1>
</div>
<div data-role="main" class="ui-content">
    <ul data-role="listview" data-inset="true">

        <li>
            <a href="#page5" data-transition="slide">
                <img src="images/icon1.jpg">
                <h2>Search Soccer Events</h2>
                <p>Find soccer meets near you</p>
            </a>
        </li>
        <li>
            <a href="#page6" data-transition="slide">
                <img src="images/icon2.png">
                <h2>Create an Event</h2>
                <p>Have an event you would like to invite people to?</p>
            </a>
        </li>
        <li>
            <a href="#page5" data-transition="slide">
                <img src="images/icon4.png">
                <h2>Help Center</h2>
                <p>FAQ's and further guidance on the app</p
                        ></a>
        </li>
        <li>
            <a href="#page1" data-transition="slide">
                <img src="images/icon3.png">
                <h2>Settings</h2>
                <p>Make changes to the app</p
                        ></a>
        </li>
        <li>
            <a href="#page1" data-transition="slide">
                <img src="images/icon5.png">
                <h2>The Team</h2>
                <p>Meet the team behind the app, the co-founders, developers etc.</p
                        ></a>
        </li>
    </ul>
    <div data-role="footer">
        <div data-role="navbar">
            <ul>
                <li><a href="#page1" data-icon="user">Profile</a></li>
                <li><a href="#page1" data-icon="location">Find Events</a></li>
                <li><a href="#" data-icon="calendar">Calendar</a></li>
                <li><a href="#" data-icon="info">Help Center</a></li>
                <li><a href="#page7" data-icon="camera">Camera</a></li>
            </ul>
        </div>
    </div>
</div>

Devnsyde
  • 1,297
  • 1
  • 13
  • 34
Mahdi
  • 153
  • 2
  • 16

1 Answers1

-1

From my understanding you want to achieve the successful login of the user to be displayed in your app, after successful login user should be able to see the username at the top of the app, such solution can be implemented using simple script in php combined with html as well , i have checked and i found a similar answer to same question, see this post it should help HTML PHP Display username after success login

Community
  • 1
  • 1
Hashes
  • 110
  • 8
  • Thanks for the link, however I am struggling to see how I can adapt this to my html page. Are you able to provide any more assistance? – Mahdi Mar 28 '16 at 21:03
  • Guys... what he posted is an answer for normal websites. Cordova / PhoneGap doesn't have a server which is able to run php. You need to run php scripts via ajax (jquery). Running PHP directly inside an application (phonegap / cordova) **isn't** possible – Sithys Mar 29 '16 at 06:40
  • I don't understand who downvoted this, it dosnt matter what platform your using , your using cardova phonegap build to package your app for testing in.multiple platform, however your question is the implementation of the login needs more than just php or html , now what I have provided you is an example of auth login and how would you be able to demonstrate the username in nav bar after login in. Your question is unclear, you want user access auth login? Or you want to know how to implement this via sql or Apache? Or you want both with the use of cardova phonegap build!! – Hashes Mar 29 '16 at 10:56