0

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

5
Contributors
14
Replies
15
Views
7 Years
Discussion Span
Last Post by cwarn23
0

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>

0

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>
0

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

0
<?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.

Edited by cwarn23: Added info

0

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'];
}
0

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

0

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

0

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...

0

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'];
?>
0

Hi,

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

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

0

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 ?

0

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?

0

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']);
}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.