Forum Moderators: coopster

Message Too Old, No Replies

PHP and user names

         

dave1236

4:31 am on Oct 2, 2004 (gmt 0)

10+ Year Member



Here is the situation:

I have implemented a login page for visitors who wish to register for my site. It is not necessary, but many users will likely want to take advantage of this (they get credits).

After they have logged in, I want to pass their user name back to my main page and combine it with another variable from a drop down list. When a selection is chosen, I want the user name to be be appended to the end of the [info] field.

Here is the main page code:
<form name="form1" method="post" action="ABC.php">
<select name="Info" id="info">
<option value="na">Find out more</option>
<option value="bob50-20">1</option>
<option value="bob51-20">2</option>
<option value="bob52-20">3</option>
</select>
<input type="submit" name="Submit" value="Go">
</form></td>

I want to add the user name to the end of the "bob50-20" code.

On the ABC.php page, I get the value of "info" as such:
<?php print $_POST[info];?>

I cannot simply combine the two to get a new tag, since certain parts of the page use switch to echo the "info" value, and other areas CANNOT include the user name. How do I get the user name to be appended to whatever [info] is?

dave1236

4:45 am on Oct 2, 2004 (gmt 0)

10+ Year Member



I know I can use sessions and cookies to some degree, but do not understand how I would be able to do this. For example, it does not help me to have a new session created each time a registered user comes to the site unless I can get the session variable to be equal to the user name.

mincklerstraat

8:43 am on Oct 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



dave,

One of the beautiful things about sessions is you can store lots and lots of 'variables'. You do this, after starting a session, by simply doing this:
$_SESSION['desired name'] = 'value';

Once you've started a session, this value is then available as:
$_SESSION['desired name'];

All you have to do to make this user name available to other pages is to set it as a session value.

Second bit of information: the concatenator, '.' (it's just a period). You add this to 'add' strings to strings, not in the mathematic sense, but in the sticking-them-on-the-end sense.
$f = 'I will not eat ';
$g = 'green eggs and ham';
$f.$g = 'I will not eat green eggs and ham';

It's not apparent from your code what variable corresponds to the user name. But somewhere you'd want to use this concatenator, like maybe, if you set the session variable 'user_name', you could do it this way:
<option value="bob50-20".$_SESSION['user_name']>1</option>

dave1236

2:06 am on Oct 3, 2004 (gmt 0)

10+ Year Member



Minck:

Now i am thoroughly confused. I tried what you suggested, but nothing worked. But looking deeper into the issue, I realized that my trans-SID is turned off ( I use Yahoo for my hosting and it looks like I do not hae access to the php.ini file - not sure though). Anyways, does this mean that I have no solution...I can write to my databse fine..but i cannot see a workaround. If I use a form, how do i set the variables value to be whatever the user_name is?

I am thoroughly confused now.

dave1236

3:21 am on Oct 3, 2004 (gmt 0)

10+ Year Member



I figured it out....at least how to get sessions running. I am not so confused now. Let's see if I can get the rest to run.

dave1236

4:15 am on Oct 3, 2004 (gmt 0)

10+ Year Member



Well, I got what I wanted to work. However, while I got the desired output, I realized that this solution corrupted the next page in my file.
This is how my option was structured:

<select name="123" id="123">

<option value="abc.<?php print $_SESSION[logname];?>">abc</option>

I got the desired output... (abc.loginname)
but when this option is passed to the next page, using this command:

<a href="http://www.xyz.com/click-123-456?sid=<?php print $_POST[123];?>" target="_blank" >XYZ</a>

my SID became: abc.loginname (which is fine for most of what I need)

But there are areas where of the page where i echoed the id="123" and not that area is blank. Additionally, there are other links where I just need "abc" and not the login name.

I guess my issue now is how do I setup my form to identify my loginname separately, and pass the two pieces separately so that my echoes work and the links just needing id="123" work as well?

Thanks! (this has been a great learning experience!)

dave1236

2:42 am on Oct 4, 2004 (gmt 0)

10+ Year Member



I got it!

mincklerstraat

8:45 am on Oct 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Congrats. Hope you didn't pull too much hair out in the mean time. Don't worry, we've all been there. What I posted at the top probably would have looked like Chinese to me too a few years ago when I was taking my first steps in php.