Value disappears on Refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
schwarzwolf
Forum Newbie
Posts: 7
Joined: Sat May 30, 2009 10:17 am

Value disappears on Refresh

Post by schwarzwolf »

Code: Select all

<form><input type="text" name="readonly-field" readonly onfocus="this.blur()" /><input type="button" value="Add" onClick="N2.value = '<?php echo $_SESSION['username']; ?>', this.disabled=true N7." id="submitN2" /></form>
Well that's the important part of the code, It changes input text value when u click that button but everytime I refresh, that new value disappears, is there a way to keep it there without making a database?

Thx in advance.
johnd123
Forum Newbie
Posts: 5
Joined: Thu Dec 20, 2007 6:47 pm

Re: Value disappears on Refresh

Post by johnd123 »

im not sure i understand what your refering to: new value disappears

What new value?? do you mean the button value?

Code: Select all

<input type="button" value="Add" onClick="N2.value = '<?php echo $_SESSION['username']; ?>', this.disabled=true N7." id="submitN2" />
if so, ensure you have session_start(); at the top of the page

if not can you explain in more detail :D
schwarzwolf
Forum Newbie
Posts: 7
Joined: Sat May 30, 2009 10:17 am

Re: Value disappears on Refresh

Post by schwarzwolf »

Code: Select all

<form><input type="text" name="readonly-field" readonly onfocus="this.blur()" /><input type="button" value="Add" onClick="N2.value = '<?php echo $_SESSION['username']; ?>', this.disabled=true" id="submitN2" /></form>
This:onClick="N2.value = '<?php echo $_SESSION['username']; ?>',

That function adds a value to a text field, The value is username, I don't have troubles with that, but I want that value (username) to never disappear because when I refresh page the value is not longer there, I'd like to change value permanently.

I'm making a form for a tournament so when someone logs on and click on add (<input type="button" value="Add") the form will register their name and will stay there untill I erase it, that's the main point of all this.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Value disappears on Refresh

Post by mikemike »

If you want the field to constantly say the users username until they change it then just have value="<?=$_SESSION['username']?>" in the field attributes:

Code: Select all

<input type="text" name="username" value="<?=$_SESSION['username']?>" />
schwarzwolf
Forum Newbie
Posts: 7
Joined: Sat May 30, 2009 10:17 am

Re: Value disappears on Refresh

Post by schwarzwolf »

No Bro, let's do it step by step so you'll get the point:
When Tournament Registration is up:
User Login
He goes to Tournament Page
There is a button that is named Add (it is suppouse to register the username on the tournament bracket field, that field is the text field) and it adds his username on a text field.
Then if he goes to other sites or refresh site, his name will be there still but remember *¡Only If He Clicked The Button!*, that means only if he registered for the tournament.

Now the problem is that on my code he can click the add button and yes his username appears but when page is refreshed the username is gone. So I need to permanently change the value of that text field only if he clicks that button.

I hope it's clear now.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Value disappears on Refresh

Post by mikemike »

If I'm understanding you right you need to save the value into a database or a cookie - probably cookie if the user isn't registering first.
schwarzwolf
Forum Newbie
Posts: 7
Joined: Sat May 30, 2009 10:17 am

Re: Value disappears on Refresh

Post by schwarzwolf »

umm is that the only way? I mean the cookie can be lost when they erase their history and well I got some troubles with my databases that's why Iwas looking another way, maybe something that can really modify the html tags idk.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Value disappears on Refresh

Post by mikemike »

That would be the two best ways, yeah. I'm sure there are many other far over-complicated methods too though
schwarzwolf
Forum Newbie
Posts: 7
Joined: Sat May 30, 2009 10:17 am

Re: Value disappears on Refresh

Post by schwarzwolf »

Ok tyvm
Post Reply