Jump to content

user profile form


ibolui

Recommended Posts

hi, i am facing a weird problem with my first attempt at flex, php and mysql. please pardon me if this is not the correct place to post my question.

 

i had a form created using flex and json, with php as the backend. below are segments of my codes..

 

//get the raw JSON data and cast to String
var rawData:String = String(event.result);
var user = JSON.decode(rawData);

first_name.text = user.first_name;
last_name.text = user.last_name;
email.text = user.email;

if (user.gender == "male") {
male.selected = true;
} else {
female.selected = true;
}

var bday:Date = new Date(user.birthday);
day.selectedIndex = bday.getDate() - 1;
month.selectedIndex = bday.getMonth();
year.selectedIndex = year_array.indexOf(bday.getFullYear().toString());

........

 

echo json_encode($_SESSION['user']);

 

when i first load the page, everything is being populated correctly on the flex frontend. however, when i refresh the page using f5, the birthday fields are incorrect. in the sense that it becomes 1 jan 1970.

 

i tried to print out the value of user.birthday and it is indeed 1 jan 1970. but i am not sure why it has become this value..

Link to comment
https://forums.phpfreaks.com/topic/107258-user-profile-form/
Share on other sites

If it initially shows the correct date, then it's probably not a sql problem.  Might possibly be php's fault but we'd have to see some php code, particularly the code that uh..interfaces with json/flex or whatever (not really that keen on those..don't really know how that works..), possibly even the php code that gets the info from the db.

Link to comment
https://forums.phpfreaks.com/topic/107258-user-profile-form/#findComment-549971
Share on other sites

hmmm.. i think i found where the problem lies..

 

$user_temp = $_SESSION['user'];

$user_temp->birthday = date("n/j/Y", $user_temp->birthday);

echo json_encode($user_temp);

 

in my code i tried to create a temp var to store $_SESSION['user'], and then edit the birthday inside. however i think the $_SESSION['user']->birthday has also been edit. how do i actually prevent this :P

Link to comment
https://forums.phpfreaks.com/topic/107258-user-profile-form/#findComment-549991
Share on other sites

yeah..no. I was wrong.  However, I was poking around, and it seems that if $_SESSION['user'] is an object, and you do

 

$user_temp = $_SESSION['user'];

 

$user_temp now becomes a copy of the whatever class $_SESSION['user'] is, but it does not carry the information (I think that's why it's showing the wrong date, or rather, a default of the first date it can show).  I think you are gonna have to just forget about using $user_temp and just use your session variable, or, if I'm reading this thing correctly, you might be able to do

 

$user_temp =& $_SESSION['user'];

 

 

Link to comment
https://forums.phpfreaks.com/topic/107258-user-profile-form/#findComment-550002
Share on other sites

emm.. i not really sure but i did tried using =& but the outcome is not what i wanted. basically i used $user_temp = $_SESSION['user'] because i want to change some fields of the user, but i do not want to change the instance inside session. hence i thought i could create a new variable with a copy of the user instance in session. but upon changing the $user_temp, the user instance inside session is also changed as well...

Link to comment
https://forums.phpfreaks.com/topic/107258-user-profile-form/#findComment-550018
Share on other sites

Man I don't know then...if you wanted to create a copy without changing the original, then according to the manual, you had it right (without the &)...so...I'm not sure why it would change the other one...but like I said, I'm a complete newb when it comes to oop. 

 

Sorry I couldn't be of help :(

Link to comment
https://forums.phpfreaks.com/topic/107258-user-profile-form/#findComment-550020
Share on other sites

i did some testing and realise that if i do this,

 

$aaa = 123;
$bbb = $aaa;
$bbb = 456;

 

$aaa will remains as 123. but if i did this,

 

class c {
var $x;
}
$aaa = new c();
$aaa->x = 123;
$bbb = $aaa;
$bbb->x = 456;

 

$aaa->x will become 456. but i do not want $aaa->x to change..

 

i am quite new to this also. someone enlighten me how to do it?

 

Link to comment
https://forums.phpfreaks.com/topic/107258-user-profile-form/#findComment-550207
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.