Hi PPL,

I have a table in my web page which will be displayed when I select an option from a dropdown box. The table appears as follows:

Username    Assignment         Date                    Update
me                  work             2010-01-21      (submit button)
you                 hello             2010-01-20       (submit button)

Now when i click the submit button a form will open in the next page like this:

Username:          (text box)
Assignment:        (text box)

I am using session to pick the Username from the table and to be displayed in the form on the next page...the code on the first page is

But, when I click the submit button for the username:me , in the form page the username:you is being displayed.... WHAT IS THE PROBLEM!!!!!!! I CAN'T FIGURE IT OUT :(
Here is the code:

<?php
session_start();

//rest of my code
$_SESSION['Username']=$row['Username'];
?> 

//code on second page for the form is

<td><input readonly="Username" type="text" name="Username"  value="<?php  session_start(); echo $_SESSION['Username']; ?>"></td>

Thanx in Advance

i dont see any wrong in your code... if you get wrong value... i recommend reviewing the value being passed on $_SESSION. I assume you had a drop down list.. make sure their value is correct.
<?php
$sql = mysql_query("YOUR QUERY HERE");
?>


<select name='username'>
<?php while($row=mysql_fetch_array($sql)){ ?>
<option value='<?=$row?>'><?=$row?></option>
<?php } ?>
</select>

i dont see any wrong in your code... if you get wrong value... i recommend reviewing the value being passed on $_SESSION. I assume you had a drop down list.. make sure their value is correct.

<?php
$sql = mysql_query("YOUR QUERY HERE");
?>


<select name='username'>
<?php while($row=mysql_fetch_array($sql)){ ?>
<option value='<?=$row['username']?>'><?=$row['username']?></option>
<?php } ?>
</select>

Hey this is a just a session variable. Is it?

Not an array.Is it? from your it looks so?

after "me" , "you " came , the session value is now "you".

otherwise it should be array and try to use ID to map names.

My understanding is this.. :)

Hi PPL,

I have a table in my web page which will be displayed when I selec


t an option from a dropdown box. The table appears as follows:

Username    Assignment         Date                    Update
me                  work             2010-01-21      (submit button)
you                 hello             2010-01-20       (submit button)

Now when i click the submit button a form will open in the next page like this:

Username:          (text box)
Assignment:        (text box)

I am using session to pick the Username from the table and to be displayed in the form on the next page...the code on the first page is

But, when I click the submit button for the username:me , in the form page the username:you is being displayed.... WHAT IS THE PROBLEM!!!!!!! I CAN'T FIGURE IT OUT :(
Here is the code:

<?php
session_start();

//rest of my code
$_SESSION['Username']=$row['Username'];
?> 

//code on second page for the form is

<td><input readonly="Username" type="text" name="Username"  value="<?php  session_start(); echo $_SESSION['Username']; ?>"></td>

Thanx in Advance

<?php
session_start();

//rest of my code
$_SESSION['Username']=$row['Username'];
?> 

//code on second page for the form is

<td><input readonly="Username" type="text" name="Username"  value="<?php  session_start(); echo $_SESSION['Username']; ?>"></td>

That code is invalid and should be as follows:

<?php
session_start();

//rest of my code
$_SESSION['Username']=$row['Username'];
?> 

//code on second page for the form is

<td><input readonly="Username" type="text" name="Username"  value="<?php echo $_SESSION['Username']; ?>"></td>

Note that the page must start with session_start(); before any browser output otherwise errors will occur.
enjoy.

If even it doesn't works for you, try like this it may works..

if(isset($_SESSION['Username'])
{
  unset($_SESSION['Username']);
  $_SESSION['Username']=$row['Username'];
}

Hi Zodiac,

I think u r correct... I have to use session arrays... I don't kow how to do it... coz my array is a variable $row... How do i do it...

I tried the following code:

In the first page:

<?php
session_start();

$my_array=array($row['Username']);
 
$_SESSION['Username']=$my_array;

?>
In the second page:

<?php  session_start();
 
// loop through the session array with foreach
foreach($_SESSION as $key=>$value)
    {
    // and print out the values
    echo $value;
    }
 ?>

Any suggestions..

Thanx in advance

Second page should be changed to the following.

<?php  session_start();
 
// loop through the session array with foreach
foreach($_SESSION['Username'] as $key=>$value)
    {
    // and print out the values
    echo $value;
    }
 ?>

Hi Zodiac,

I think u r correct... I have to use session arrays... I don't kow how to do it... coz my array is a variable $row... How do i do it...

I tried the following code:

In the first page:

<?php
session_start();

$my_array=array($row['Username']);
 
$_SESSION['Username']=$my_array;

?>
In the second page:

<?php  session_start();
 
// loop through the session array with foreach
foreach($_SESSION as $key=>$value)
    {
    // and print out the values
    echo $value;
    }
 ?>

Any suggestions..

Thanx in advance

Hi,

:( I tried that, nope not working...

When i Click on the update for username:me, the Username:you is being displayed in the textbox...

As someone said, I think,since the Username:you is the last username being displayed it is stored in the session()...

Is there nyother way I can try, to solve this prb...

Well when you assign username wouldn't you do it like the following?

<?php session_start();
if (isset($_POST['user']) && !empty($_POST['user'])) {
$_SESSION['Username']=stripslashes($_POST['user']);
}
?>
<?php session_start();
echo $_SESSION['Username'];
?>

Hi,

Do you think I can use $_POST for this...

If it is possible, can u help me with the code...

Hi,

Do you think I can use $_POST for this...

If it is possible, can u help me with the code...

Yes but why can't you use $_POST ?

I can't use $POST coz the $row should be assigned a value to post it to the nextpage...

Since I am viewing the list of Username in a table, I won't have a value to submit it to the next page... Am I CORRECT?

I can't use $POST coz the $row should be assigned a value to post it to the nextpage...

Since I am viewing the list of Username in a table, I won't have a value to submit it to the next page... Am I CORRECT?

Well that one is on opinion. You could a- use the $_POST as the username after checking it exists from the database or b- fetch from mysql which will have the same value as $_POST; That is if your using a login form. If you like below is a script to show how to assign to sessions. (Page 1)

<?php
if (isset($_POST['user']) && !empty($_POST['user'])) {
$r=mysql_query('SELECT * FROM `users` WHERE `user`="'.mysql_real_escape_string(stripslashes($_POST['user'])).'" AND `password`="'.mysql_real_escape_string(stripslashes($_POST['password'])).'"') or die(mysql_error());
if (mysql_num_rows($r)==1) {
$_SESSION['Username']=stripslashes($_POST['user']);
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.