Show users username

local userName local userNameText function scene:create(event) local screenGroup = self.view local background = display.newImageRect("insta.jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) local userNameText = display.newText(userName, 100, 200, native.systemFont, 16 ) --\<------ take the "local" off here, you have it local near the top myText:setFillColor( 1, 0, 0 ) screenGroup:insert(userName) --\<----- you cannot insert a string into a group. This should be userNameText end

You insert display objects into groups.  

You need to give userName an actual value, for example:

local userName = "comeUp264"

Then, it will work.

And what Rob said:

screenGroup:insert(userNameText)

Okay it works . But how do I make it show any users user name and not just mine ?

To do this, you would have to retrieve the name from a list if you make one. I can’t help too much with this, so start a new topic on it.

Where do you expect the username to come from?

My Mysql php database . I have it setup with my PHP . My app is connected to the database 

Do you want it to show the user name of the person who owns the device? 

Do you want to get a list of all users or some group of users and give the device owner the ability to see a list of users?

If it’s the first option, why not save the username locally and display it from your local information. You have a login process so you could keep the username they logged in with locally.

How do I do that ?

Which one? 

Oh sorry . the first one .

Are you having them type their username in at some point before you want to show this?  

Is this a separate scene from your login scene?

Are you remembering the users username and password so they don’t have to type it in every time?

Do you know how to save the username and password locally so they don’t have to type it in every time?

Do you know how to pass data between scenes?

If you don’t know those answers, you should do some research about how to save data, how to pass data between composer scenes, etc.

  1. No as soon as the sign in they will go to their newsfeed page , and when they click their profile their information will be shown to them . (Profile pics , username , pics posted etc) . 
  2. Yes this is a separate scene from login .
  3. I want to but I don’t know how .
  4. No I don’t.
  5. I don’t think so

Okay, you are going to need another PHP script. Call it profile.php. You will use “GET” instead of “POST”. I’m assuming you eventually want to be able to get any one’s profile.

http://yoursite.com/profile.php?q=playersusername

Then that script will query your MySQL database to find the profile information for that username and you will probably have a second query to get pics posted etc. Put all of that into a PHP Associative Array (similar to a Lua table).  Then

echo (json\_encode(yourProfileTable));&nbsp;

that will create data that can be passed back to Corona’s network.request()'s network listener function.  This means that you will have to have another network.request() to request your profile.php script that includes the username as part of the URL. You will need a unique listener function for this. When you get it, you will do something like:

local profile = json.decode( event.response )

at that point you will have a table named profile that will have all of your data that you fetched in your script and added to the associative array.

Now to do this, you will have to keep the username in memory where they logged in.  The easiest way to do this is to use the composer.setVariable() and composer.getVariable() functions, when you login call:

composer.setVariable(“username”, yourusernametextstring )

Then when you’re ready to make that network request you can:

local profile local function yourProfileListener( event ) &nbsp; &nbsp; &nbsp;if not event.isError then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; profile = json.decode( event.response ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- do whatever you need to do with your profile &nbsp; &nbsp; &nbsp;end end local URL = "http://yoursite.com/profile.php?q=" .. composer.getVariable("username") network.request(URL, "GET", yourProfileListener)

This code will likely be part of your profile.lua scene where you’re going to show all of this.  Most likely you will code this in your scene:show()'s “will” phase and you will create your various display objects here.

Rob

Do I do this :

Then that script will query your MySQL database to find the profile information for that username and you will probably have a second query to get pics posted etc. Put all of that into a PHP Associative Array (similar to a Lua table). Then echo (json\_encode(yourProfileTable)); 

in PHP ?

Correct

How do I do this :

Then that script will query your MySQL database to find the profile information for that username and you will probably have a second query to get pics posted etc. Put all of that into a PHP Associative Array (similar to a Lua table).

How do I put the username and pics in this table ?

Is this a good start ? :

$profile = array("", "", "");

Where do I go from there ?

Maybe this tutorial will help:

https://www.w3schools.com/php/php_mysql_create_table.asp

How does that help ?

@comeUp264 (changed to HRH…) You might want to consider hiring someone to do this for you or to teach you.