sneiland Posted March 9, 2007 Share Posted March 9, 2007 This is probably an obvious one but i cant see why i am getting this problem. Basically i have a user id stored in session variable eg user_id =1. I have a simple forum that i created myself that inserts this session variable into the db with the persons entry. eg insert into forum value (session[user_id],'$_post['content']); This is all working fine until i go to edit this post from say the moderator account. I set the user_id for the "replace into db" initially to my session value unless i have selected to edit someone elses post, then i set it to the value submited back from the <form action=self> i get as far as selecting the contents from db only for the session variable holding my id to change to the value of the user_id selected from the db. //if self submit //if this is a new entry into forum then get my id from session variable if($_POST['user_id']=="") { $user_id=$_SESSION['user_id']; } else { //get user value from posted form $user_id=$_POST['user_id']; } //if this is not a new post get the current values in table $query=" SELECT topic_id, topic_subject, user_id FROM forum WHERE topic_id = 1; if($result=queryDB($query)) { while($resultrow=mysql_fetch_array($result)) { $debug.="D Session user_id: ".$_SESSION[user_id]."<br />"; //at this point my session id is one $topic_id=$resultrow['topic_id']; $subject=$resultrow['topic_subject']; $user_id=$resultrow['user_id']; $debug.="E Session user_id: ".$_SESSION[user_id]."<br />"; //at this point my session variable has changed to two the value stored in $user_id } } //replace into forums Link to comment https://forums.phpfreaks.com/topic/41959-session-variable-becoming-linked-to-post-variable/ Share on other sites More sharing options...
Glyde Posted March 9, 2007 Share Posted March 9, 2007 If you have access to php.ini, ensure that register_globals isn't on. Also, when you are setting the session, are you calling register_session()? If so, then $_SESSION['user_id'] would become a reference to the variable $user_id. Whenever $user_id is changed, $_SESSION['user_id'] would be changed as well. Link to comment https://forums.phpfreaks.com/topic/41959-session-variable-becoming-linked-to-post-variable/#findComment-203484 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 If you have access to php.ini, ensure that register_globals isn't on. Also, when you are setting the session, are you calling register_session()? If so, then $_SESSION['user_id'] would become a reference to the variable $user_id. Whenever $user_id is changed, $_SESSION['user_id'] would be changed as well. You will have to set $_SESSION['user_id']=$user_id; to a session then you can use it ok. Link to comment https://forums.phpfreaks.com/topic/41959-session-variable-becoming-linked-to-post-variable/#findComment-203534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.