variable passing help!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
just a member
Forum Newbie
Posts: 5
Joined: Tue Aug 08, 2006 6:58 am

variable passing help!!

Post by just a member »

Hi,
i have an html page lets say page.html which contain a form with input field called username and i have two php pages lets say page1.php and page2.php. now the problem is that i need to use the variable username in page1.php and page2.php but how i can do that i know i should use a $_session but i don't know how sorry about my question but i just start learning php and i need it in my project so if any body can help me with a siple example i will be very thankfull

kind regards
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Have you got any code yet?
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

HINT:

Code: Select all

session_start();

$_SESSION['username']= ...
just a member
Forum Newbie
Posts: 5
Joined: Tue Aug 08, 2006 6:58 am

Post by just a member »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


thank you for response,
yes i have code
the html page called log_in.html and it contain form with username field

Code: Select all

<?php session_start();
$_SESSION['username']='username';
?>
 <form method="POST" action="log_in.php" name="myform" onSubmit="return validateform( this.form )"  >
<input name="username" size="20" style="border: 1px inset #000000" dir="ltr" maxlength="8">
and i have logged_in.php and there i don't have any proplem the problem is in personal_information.php where i need to use the variable username to specify the retrieving from the database, i use postgresql !

i'm so confused about using $_SESSION i meen i should put session_start(); in every page or what ??

kind regards


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

Code: Select all

$_SESSION['username']=$_POST['username'];
just a member
Forum Newbie
Posts: 5
Joined: Tue Aug 08, 2006 6:58 am

Post by just a member »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi again,
sorry for many question but i realy need to understand this.

now in log_in.html i should  code with

Code: Select all

<?php session_start();
$_SESSION['username']='$username';
?>
and thin at personal_information.php i should start the code with

Code: Select all

<?php session_start();
$_SESSION['username']=$_POST['username'];
am i right!? if so how i can use the value of username in the SQL query?? should i use it as 'username' or '$username' or what??!

sorry again for my silly questions.

kind regards


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

Thats it, your sql query would be like:

SELECT * from table where username = '$username'
just a member
Forum Newbie
Posts: 5
Joined: Tue Aug 08, 2006 6:58 am

Post by just a member »

thank u very much ,
but i;m very disappointed because it didn't work the query didn't give me any results i don't know what is the problem but when i try the code with a specific username it give me the results i want so, i think the proplem with passing the variable from the html form!!!???

kind regards
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

$username = $_SESSION['username'];

before your sql query
just a member
Forum Newbie
Posts: 5
Joined: Tue Aug 08, 2006 6:58 am

Post by just a member »

:( :( :(
it didn't work!!!!!!

:( :( :(

kind regards
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

<?php session_start();
$_SESSION['username']='$username';
?>
That is NEVER going to work because variabls inside singles quotes dont get parsed

it needs to be like this

Code: Select all

<?php session_start();
$_SESSION['username']=$username;
?>
Infact, looking at your code, i think what you need is

Code: Select all

<?php session_start();
$_SESSION['username']=$_POST['username'];
?>
Post Reply