Pavlos1316 Posted June 5, 2008 Share Posted June 5, 2008 Hi 1st code is used in my login.php so combined with the next code which is placed in my members pages are used for user authentication: if(mysql_num_rows($result)>0){ //Login Successful //Regenerate session ID to //prevent session fixation attacks session_regenerate_id(); $member=mysql_fetch_assoc($result); $_SESSION['SESS_ID']=$member['ID']; //Write session to disc session_write_close(); header ("location: members_area.php"); exit(); <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_ID']) || (trim($_SESSION['SESS_ID'])=='')){ header("location: http://www.sonophoenix.com/"); exit(); } ?> Now I have another procces.php which is submitting a form that only a member can submit. How can I get the member's username in my db when submitting the form? Thanks Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/ Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Share Posted June 5, 2008 ok i would do this .. chnage where appropriate <?php $getruser="Select username from users where id='".$_SESSION['SESS_ID']."' "; //getting user with id... change select "username - to what ever users are in db" and "users - what ever users are" $getuser2=mysql_query($getuser) or die("Could not get replies"); while($getuser3=mysql_fetch_array($getuser2)) { echo $getuser3['username']; }// chnage to what it is in you Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558122 Share on other sites More sharing options...
Pavlos1316 Posted June 5, 2008 Author Share Posted June 5, 2008 Should I put any of the 2 codes I am using in my proccess.php or just what you write? 2. If I understand this will only echo the username not post it in my db? Cause that is what I want. To post username with other info of the form Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558126 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Share Posted June 5, 2008 sorry didnt really understand... you could still post it in the db just set $user = $getuser3['username']; then add $user into db Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558129 Share on other sites More sharing options...
Pavlos1316 Posted June 5, 2008 Author Share Posted June 5, 2008 I allready did but I get err msg 'Could not get replies' Should I also include in my .php the code I use for member's pages? (second one) Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558131 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Share Posted June 5, 2008 show me your full page u have now with script i sent Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558153 Share on other sites More sharing options...
Pavlos1316 Posted June 5, 2008 Author Share Posted June 5, 2008 My code is too big [300 lines] I thing I know where the problem is but I don;t know how to fix it. Here is the situation 1. my procces.php connects with db2 takes data from the form and post them in db2. 2. username exists in db1. so to retreive id I have to make a connection with db1. Right? Plus I have to post it in db2 3. how is that done in the same php file?? Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558156 Share on other sites More sharing options...
prcollin Posted June 5, 2008 Share Posted June 5, 2008 you have to have to create two connect.php files one for each db and include both the files then you can call both db in the page you want to use them both with. Then you just write the code in the order that you want the events to occur, i believe. I just did something like this a short while back but cant find the code cause my laptop crashed Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558160 Share on other sites More sharing options...
Pavlos1316 Posted June 5, 2008 Author Share Posted June 5, 2008 Did it!!! in the same php file <?php 1st i connected to my db1 where the username is>>>>> use your code to retreive member's username>>>>and close my db1 connection with mysql close(); Then I connected to my db2 which stores the form info. And it's done!!! With your CODE help....!!!! Thanks...! ?> Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558203 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Share Posted June 5, 2008 ahhh good glad to see it worked Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558223 Share on other sites More sharing options...
prcollin Posted June 5, 2008 Share Posted June 5, 2008 ahhh good glad to see it worked Thats good I just create two files cause it is easier for me to keep track of glad it all worked out!! Link to comment https://forums.phpfreaks.com/topic/108805-solved-retreive-members-username/#findComment-558231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.