Forum Moderators: coopster

Message Too Old, No Replies

want to autopopulate form fields from database

         

mgworek

9:07 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



I have a working form that submits info into a database.

I want to take a few fields about the poster (name, email) and hide them and have them filled out from my user table, which is the same database but different table then where the form data is being sumbitted.

I must be searching for thr wrong thing cause i am not finding any information on it.

Any suggestions on where to look would be great.

Thank you.

jatar_k

9:12 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could just issue a select before you insert and grab the info to use in your insert query

mgworek

9:43 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



I have written a script before to list data in a database but what does it need to only select the information of the logged in user?

jatar_k

9:51 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> only select the information of the logged in user

do you use a session or cookie where you could grab information about them to use in the select?

mgworek

10:08 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



I will have to look for that info.

I did not build the login system, I am using aMember. I know it is using something, the user can edit their profile so I will look into that and let you know.

Thanx

mgworek

10:11 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



it is using a cokkie based login...

"Using php_include
This plugin allow you add cookie-based login for protected-pages. It is particularly useful for adding paid membership support to an existing PHP-based "application.

jatar_k

10:18 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



probably take a look at the login script and see how/what it sets in the cookie

this might also be able to tell you

echo "<p>cookie values:<br><pre>";
print_r($_COOKIE);
echo "</pre>";

mgworek

10:27 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



their php code in scrambled so i can look at the login script, i will try and find the cookie though.

mgworek

10:30 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



bit i did add their name on the screen after login by adding in

Welcome, {$smarty.session._amember_user.name_f} {$smarty.session._amember_user.name_l}

jatar_k

11:26 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do either fo those values help with a query?

try echo'ing them and see if they are what you need

mgworek

4:54 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



those fields didnt work for me.

I did email the company and they dont me to use this

You can use $_SESSION[_amember_user] variable.
After login, user info stored in above array.

jatar_k

5:12 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ah so it is a session then as opposed to a cookie

this will show you all the session vars

echo "<p>cookie values:<br><pre>";
print_r($_SESSION);
echo "</pre>";

mgworek

6:23 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



I dont get a print out for ($_SESSION);

Just so you know, I have everything in one .php page.

I just with a php section to connect to database, end php. then my form. then php again to send data to database and send emails out and then end php again.

I have what you told me to put in in the first php section, so after it connects to the database, I have it trying to print out info from $_SESSION

jatar_k

6:35 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



weird, it must be in the wrong part the since they said

>>You can use $_SESSION[_amember_user] variable.

there should be a session somewhere

is there session_start() anywhere?

mgworek

6:49 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



hey, i got it working.

I looked at my protection settings on amember and had it set wrong, i set it to just phpinclude, and it told me what to put at the begining of my php code. This was the print out...

It did not give me all the fields, the fields it gave me were the defaults, none of the custom fields so their session doesn't look at information.

[_amember_user] => Array
(
[member_id] => 3
[login] => mgworek
[pass] => classified
[email] => myaddress@yahoo.com
[name_f] => marty
[name_l] => rre
[street] => 1111
[city] => 1111
[state] => UT
[zip] => 12234
[country] => US
[is_male] => 0
[added] => 2006-02-15 11:33:38
[remote_addr] => 66.147.90.118
[data] => Array
(
[status] => Array
(
=> 1
)

[1][edited by: jatar_k at 6:54 pm (utc) on Mar. 1, 2006]

jatar_k

6:56 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so to get name and email you could use

$_SESSION['_amember_user']['name_f'] for first name
$_SESSION['_amember_user']['name_l'] for last name
$_SESSION['_amember_user']['email'] for email

mgworek

7:20 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



ah ha!

before you replied, I was trying to figure it out and not getting far, I was doing
$_SESSION[_amember_user_name_f] instead of seperating them.

(sorry for any typos)

I got it working, thank you very much!

jatar_k

7:23 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



nice work mgworek

>> typos

I just examplified your email address ;)